cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Printing

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Any other suggestions? Can someone suggest a workaround for this?

How can I achieve printing a file from webdynpro?

Regards,

Harini S

Sigiswald
Contributor
0 Kudos

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

chintan_virani
Active Contributor
0 Kudos

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>

Former Member
0 Kudos

Hi,

What I want to print is a xml file from webdynpro. How do I do that with window.print(); Any workarounds?

Regards,

Harini S

Former Member
0 Kudos

Hi,

Display your XML file in a html file with a print button in it and display it in IFrame.

Former Member
0 Kudos

Hi,

window.print() works separately in the html but if used with iframe becomes useless. It is not getting called at all. Have u tried using both? Please help me.

Regards,

Harini S

chintan_virani
Active Contributor
0 Kudos

Harini,

Please go thru following . It may help you.

<b>- Chintan</b>

Sigiswald
Contributor
0 Kudos

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

Former Member
0 Kudos

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

Sigiswald
Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

Back to Start. I started from these Java Print APIs only. Anyway, will check more on that too. Thanks a lot for all ur support.

Regards,

Harini S

Sigiswald
Contributor
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

Nothing worked. Print Functionality is postponed. So will work later.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Ya. I know that. Is there any specific reason for it? Please guide me.

Also tell me if graphics or that kind of popup isn't supported by webdynpro or WAS?

Regards,

Harini S