cancel
Showing results for 
Search instead for 
Did you mean: 

Print html document

Former Member
0 Kudos

Hi, I'm trying to print a html document with this following java code but doesn't works:

public void onActionPrintEncuestaPDF(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionPrintEncuestaPDF(ServerEvent)

try{

Robot robot = new Robot();

// Ctrl+P

robot.keyPress(KeyEvent.VK_CONTROL );

robot.keyPress(KeyEvent.VK_P );

robot.keyRelease(KeyEvent.VK_CONTROL);

robot.keyRelease(KeyEvent.VK_P );

Thread.sleep(500);

//Alt+U

robot.keyPress(KeyEvent.VK_ALT );

robot.keyPress(KeyEvent.VK_U );

robot.keyRelease(KeyEvent.VK_ALT );

robot.keyRelease(KeyEvent.VK_U );

Thread.sleep(500);

//entrée

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER );

Thread.sleep(500);

}

catch(Exception e){ }

//@@end

}

This is not working because java.awt.Robot is a part of AWT package and intended for the client site, how I can make an action that when the

client push the print button. Print the html document automatly.

Regards,

Gabriel

Accepted Solutions (1)

Accepted Solutions (1)

Abhinav_Sharma
Contributor
0 Kudos

Hi Gabriel,

AFAIK client-side eventing is not possible in webdynpro. But you can try this

<a href="/people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities:///people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities. This may guide you to the right direction.

Regards

Abhinav Sharma

Answers (2)

Answers (2)

Former Member
0 Kudos

I create into KM Content on portal a file called print.html and I put the following code:

&#65279;<html>

<head />

<body onLoad="window.parent.focus(); window.parent.print();">

</body>

</html>

Because window.paren.print(); printed the code of actual iFrame. And into Web Dynpro I created a button that call the following function.

 public void onActionPrintEncuestaPDF(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionPrintEncuestaPDF(ServerEvent)	wdContext.currentPrintElement().setAtrURL("/irj/go/km/docs/documents/print/print.html");
   //@@end
}

Former Member
0 Kudos

Gabriel,

Quick and dirty solution:

1. Create HTML file within mimes folder below sub-folder with name of your component, name it for example print.html

2. Put the following inside HTML:


<html>
  <head></head>
  <body><button onclick="window.parent.print()">Print</button></body>
</html>

3. Put IFrame control on view, set url to print.html and adjust size as necessary

Valery Silaev

SaM Solutions

http://www.sam-solutions.net