Skip to Content
Author's profile photo Former Member

Webdynpro Java / Printing using NW 2004 , 2004s

Webdynpro Java / Printing using NW 2004 /2004s

Author Bio

Ritushree Saha having 2 years of exp in Java/J2EE (Struts Framework) and 2.6 years of exp in SAP.EP.NW in IBM India Pvt LTD, Kolkata.

*Company: * IBM India Pvt Ltd

Created on: 03 June 2009


WebDynpro on NW 2004/2004s using had no native support for printing and the community came up with pretty good workarounds. Therefore this is a workaround to print the view by converting the content to html.

But I had a requirement to print one of the views of the Webdynpro Java application using NW 2004/2004s. I searched in SDN but couldn’t find a consolidated document for printing using NW 2004/2004s. So after solving the requirement thought of posting the process so that other SDN viewers are helpful.


Printing using NW 2004/2004s 

WebDynpro on NW 2004/2004s using had no native support for printing and the community came up with pretty good workarounds. Therefore this is a workaround to print the view by converting the content to html.

To narrate this paper I took the scenario of displaying the “First Name, Last Name, Department” in the view and then on pressing the “Print” button on the display view the view will get printed without the “Print” button using NW 2004s.

Let’s look at the steps:

    • Create a Webdynpro Component with the view and the window.

Create a context value node name “*Employee” with value attributes “FirstName, LastName, Department”* in the Component controller

    1. Open the diagram view and perform the mapping between the component controller and the view controller.

Then in the view, select the “layout” tab create a three UI input elements for “FirstName”, “LastName” and “Department” and then a “Print” button.

Bind the UI elements with the attributes of the value node “Employee“.

Then create onAction method for the “Print” button.

Following is the code utility:

public void onActionPrint( wdEvent )


    //@@begin onActionPrint(ServerEvent)

byte[] content = new byte[4028];

try {

    content = this.displayPrint().getBytes(“UTF-8”);


// Where content is loaded with data from displayPrint() method, which is holding the HTML *page to be displayed to the user *

      IWDWindow win =wdThis.wdGetAPI().getComponent().getWindowManager()


      .getWebResource(content, WDWebResourceType.HTML)

      .getURL(),”Print Claim Details”);





} catch (Exception e) {  





public java.lang.String displayPrint( )


    //@@begin displayPrint()


IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();

// designing of the html layout


StringBuffer xml_file = new StringBuffer();



xml_file.append(“<center><b>Employee Details</b></center>”);

xml_file.append(“<br><font size=\”2\”>”);

xml_file.append(“<TABLE border=\”0\” cellpadding = \”2\” cellspacing = \”1\” width= \”100%\”>”);

xml_file.append(“<tr VALIGN=TOP>”).append(“<td><b>First Name </b></td>”).append(“<td>”).append(wdContext.nodeEmployee().currentEmployeeElement().getFirstName()).append(“</td></tr>”);

xml_file.append(“<tr VALIGN=TOP>”).append(“<td><b>Last Name </b></td>”).append(“<td>”).append(wdContext.nodeEmployee().currentEmployeeElement().getLastName()).append(“</td></tr>”);

xml_file.append(“<tr VALIGN=TOP>”).append(“<td><b>Department </b></td>”).append(“<td>”).append(wdContext.nodeEmployee().currentEmployeeElement().getDepartment()).append(“</td></tr>”);


xml_file.append(“<br><br><br><input type=\”button\” name= \”Print\” value = \”Print\” onClick=\”javascript:window.winPrint()\”/>”+

” <input type=\”button\” name= \”Close\” value = \”Close\” onClick=\”javascript:window.close()\”/></body>”);


xml_file.append(“<script language = \”Javascript\”>function winPrint(){“);

xml_file.append(“var x=document.getElementById(\”Print\”);”).append(“var y=document.getElementById(\”Close\”);”).append(“\”none\”;”).append(“\”none\”;”).append(“window.print();”).append(“\”block\”;”).append(“\”block\”;”).append(“}”);



return xml_file.toString();


Display of “Print” dialog box on click of “Print” button in the view.

Click of the button “Print” in the print dialog box the view contents will get printed without the “Print” Button.


Therefore even also we are using NW 2004/ 2004s , we can print the view in Webdynpro Java application.

Related Content

     The following blog has helped me to write this paper is:


Disclaimer and Liability Notice

This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

Assigned tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Dear Ruchesree,

             Great Blog...for making thing simple.Keep blogging.

      Indranil Chakrabarty

      Author's profile photo Kumar Prashant
      Kumar Prashant
      Hi Ritushree,

      What is the difference between the blog you have referred and the one you have created..?


      Author's profile photo Former Member
      Former Member
      Ritu ,
      i m using the same code that u created but in that there is error like "ABSTRACT STRING BUILDER IS NOT VISIBLE " som please help me that how can i solve it whether i have to add any class or ..
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      Can you mail me your files where you wrote the code for printing and the screen shot of the error when it is occuring..
      Author's profile photo Former Member
      Former Member
      Hi Ritushree,

      Your blog really helped me with printing my WD View. Thanks a lot. Keep blogging.