cancel
Showing results for 
Search instead for 
Did you mean: 

Printing of views without Netweaver 2004s (Solution 1)

hschaefer123
Participant
0 Kudos

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

http://hostwww/irj

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Holger,

This Solution helped me a lot. Thanks a lot.

Sreekanth