on 07-06-2006 3:35 PM
Hi,
on our customer needs i had to develop the possibility of printing the contents of a view.
This feature seems to be part of NetWeaver 2004s, but what if customers does not have 2004s at the moment?
Beside the forum posts i figured out one solution that will quickly implement such a feature.
I implemented the following function:
public static String getPrintWindowURL() {
StringBuffer x = new StringBuffer();
x.append("<html><head><script>");
x.append("opener.print();");
x.append("</script></head>");
x.append("<body>Printing...<hr/><a href="javascript:window.close();">CLOSE</a></body>");
x.append("</html>");
String linktoFile = "";
try {
byte[] b = null;
b = x.toString().getBytes("UTF-8");
IWDCachedWebResource htmlFile = WDWebResource.getWebResource(b, WDWebResourceType.HTML);
htmlFile.setResourceName("Print.htm");
linktoFile = htmlFile.getURL();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WDURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return linktoFile;
}
Now you can popup an external window with the generated code of the former function:
IWDWindow win = wdComponentAPI.getWindowManager().createExternalWindow(getPrintWindowURL(), "Print", false);
The Solutions depends on the posibility, to reach the calling window (opener) via JavaScript and to invoke the print() function.
Disadvantages of this solution:
The solution works fine in a standalone Web Dynpro App or in a Local Portal.
As an embedded iview inside a portal you run into JavaScript Security Policies that does not allow cross domain JavaScripting, since you call the portal via an qualified domain name.
The Problem seems to be the different pathes of portal and Web Dynpro
http://www.xxx.de/irj/. (Portal)
http://www.xxx.de/webdynpro/dispatcher/. (WebDynpro)
But using a call of the portal via host entry
without using a domain, the feature works also inside the portal.
Maybe someone with better JavaScript knowdlege knows a solution for using this functionality inside the Portal
and can add some hints/tips.
Maybe this will help someone as a starting point.
Hint:
Do not try to print using the iframe printing example via the iframe.src = "window.print()". This does not work anymore cause in the meantime of some service pack the source is validated and runs into an exception (Took me some minutes to try and found out).
Best regards,
Holger Schaefer
Message was edited by: Holger Schaefer
Message was edited by: Holger Schaefer
Hi Holger,
This Solution helped me a lot. Thanks a lot.
Sreekanth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.