on 03-22-2007 10:29 AM
Hi,
I am having problem in printing a file from webdynpro.
My code gives java.awt.HeadlessException
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet prnReqAttrSet = new HashPrintRequestAttributeSet();
job.pageDialog(prnReqAttrSet);
But the same works fine as standalone Java application. But when I run it in the WAS, I get HeadlessException. Can someone help me rectify this issue?
Regards,
Harini S
The reason stands the same. WD applcations are executed in WAS and nothing happens at client side so WD framework doesnot allow you to get that print dialog box
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, this is simply not possible...
As of 2004s, the client user can print an iView. Another option is to insert some javascript that allows printing the browser window or Web Dynpro window. A user can download a file and print it locally, but not directly on the server.
Kind regards,
Sigiswald
Harini,
You can have a Button <b><i>Print</i></b> in WebDynrpo.
On click of button you need to call a HTML page located on same server.
This HTML page should contain the javascript functionality of printing. Somewhat like this:-
<script language=JavaScript>
window.print();
</script>
This will open the Printer Dialog Box as probably u require when u click on Print.
- Chintan<b></b>
Hi Harini,
In case you want to allow the client user to print the content of the Web Dynpro window as it is displayed in the browser, as of NW04s the preferred way is to use the iView print functionality (I don't know the details...). Another option, which also works on NW04, is to "inject" some javascript in your Web Dynpro application using an IFrame UI element. Note however that using javascript inside Web Dynpro is not recommended (and may very well no longer be possible in the future)! More details can be found in this post: .
In case you don't want the client user to print the Web Dynpro screen as it is displayed in the browser, but a file (xml file, Word document, PDF etc.) that resides on the server, I see only one reasonable solution: allow the client to download the file. A much more complex solution would be to render the file in the browser as HTML and use javascript to be able to print the displayed file. I can imagine it's not that complex to render an xml file as html, but it's a bit more difficult to render a Word document as html. If you have a pdf, you can create a URL to the pdf using the WDWebResource and bind the URL to an IFrame UI element. The pdf will be displayed in the browser using the Adobe Reader browser plugin, which contains a print button.
Kind regards,
Sigiswald
Hi,
My case as of now is printing one XML file on click of a button. I tried 2 cases.
1) When I use the html iframe, window.print() doesn't work though I am able to display the xml inside iframe correctly. It gives javascript error. (Object expected).
2) If I use IFrame UI element in webdynpro and bind the context to string which contains html, that works for normal text only. i.e., if <body> tag contains plain text. I am able to print without any problem. But with xml data inside <body>, tags disappear and only data inside tags get printed.
My original case deals with printing many xml files in a single click. So saving each on client machine and printing one by one is not going to work. Actually I don't want to open any file also. I'll still checking on how it can be done. Any other suggestions, please let me know.
Regards,
Harini S
Hi Harini,
In this case I see only one feasible option: the <a href="http://java.sun.com/j2se/1.4.2/docs/guide/jps/">Java Print Service</a> API. I have no experience with this API, but what you want to achieve is certainly possible. Some very simple examples can be found here: <a href="http://javaalmanac.com/egs/javax.print/pkg.html">javax.print Examples from The Java Developers Almanac 1.4</a>.
Good luck!
Kind regards,
Sigiswald
The java.awt.HeadlessException is "Thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse." Serverside you won't be able to display some print dialog on the client anyway. The "trick" is to discover and use the print services directly, without any UI. Of course, all files will be printed on (a printer connected to) the server.
Kind regards,
Sigiswald
Nothing worked. Print Functionality is postponed. So will work later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Are you using this code in your WD application ???
If yes then it won't work as the WD code is executed at the server side and not at the client side.
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.