Print html document

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

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

Similar Messages

  • All of a sudden, I can't print .html documents on Firefox (I can on IE.) What happened?

    As of yesterday, I cannot print an .html document while on Firefox. I print a lot of recipes from different sites and also was trying to print a credit card bill. I went to Internet Explorer and can print just fine there. What is going on?

    See this: <br />
    http://kb.mozillazine.org/Problems_printing_web_pages

  • Print html document from presentation server with no intervention of user

    Hello,
    I have been able to create HTML output for my smartform.
    They are saved on my machine.
    I need to print these HTML outputs as a part of process without intervention of the user.
    Is it possible?
    I have tried method 'EXECWB' of 'cl_gui_html_viewer', but that gets fired only on some action and shows the Print dialog for the selection of printer.
    It would be great if anyone can help me with us.
    Thanks
    Mona

    PDL -- thank you for your reply.
    What you gave me did spawn the print dialog allowing me to select a printer. However, when the document printed, the number of pages in the document was correct but the pages were empty except for the page x of y along the top and the name of the document along the bottom. Have you seen this before and do you know how to correct? Also, how do you suppress the info across the top and bottom of the report from printing?
    Thanks

  • How to Print Html Document (more than one page)

    I've a problem with printing my html page. I can print one page of html file, But my document is longer than one page. and i can't print it.
    who know how to print . Please Reply

    A recent article in JavaPro has a nice solution for this problem. Check out
    http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    It describes a way of using Views to break down the pages.

  • Printing HTML documents in SAP GUI for HTML

    Hi,
    I created an SAP Transaction iView with the transaction PR05 (Travel Expense Manager). Now I'd like to print the selected trips via the print function either in html or pdf.
    I already created a pdf printer and it works fine. Is there also a possibility to print and save the output of the trips as an html doc?
    Thanks in advance for your answers.
    Regards
    Joachim

    Please search for front end printing for sapgui for html and you should see some details...

  • Trouble printing HTML document

    On http://technet.oracle.com/oramag/webcolumns/2003/techarticles/clevenger_jumpstart2.html, there is no 'print' button or print friendly version of this Article. Trying to print this fine Article by Robert Clevenger results in the right margin (and words) being chopped off. If there was a frame that could be printed or if a user could hit an available 'print' button to eliminate the clutter on the left and top-hand sides, that would be a big help.
    Thanks, Charles Funderburke

    Hi Charles,
    This forum is specifically for issues relating to the OTN documentation pages at: http://otn.oracle.com/documentation/index.html
    Please try the Member feedback forum instead at:
    Community Feedback (No Product Questions)
    regards,
    Les

  • Help needed:Printing HTML file using javax.print

    Hi
    I am using the following code which i got form the forum for rpinting an HTML file.
    The folllowing code is working fine, but the problem is the content of HTML file is not getting printed. I am geeting a blank page with no content. What is the change that is required in the code? ALso is there any simpler way to implement this. Help needed ASAP.
    public boolean printHTMLFile(String filename) {
              try {
                   JEditorPane editorPane = new JEditorPane();
                   editorPane.setEditorKit(new HTMLEditorKit());
                   //editorPane.setContentType("text/html");
                   editorPane.setSize(500,500);
                   String text = getFileContents(filename);
                   if (text != null) {
                        editorPane.setText(text);                    
                   } else {
                        return false;
                   printEditorPane(editorPane);
                   return true;
              } catch (Exception tce) {
                   tce.printStackTrace();
              return false;
         public String getFileContents(String filename) {
              try {
                   File file = new File(filename);
                   BufferedReader br = new BufferedReader(new FileReader(file));
                   String line;
                   StringBuffer sb = new StringBuffer();
                   while ((line = br.readLine()) != null) {
                        sb.append(line);
                   br.close();
                   return sb.toString();
              } catch (Exception tce) {
                   tce.printStackTrace();
              return null;
         public void printEditorPane(JEditorPane editorPane) {
                   try {
                        HTMLPrinter htmlPrinter = new HTMLPrinter();
                        htmlPrinter.printJEditorPane(editorPane, htmlPrinter.showPrintDialog());
                   } catch (Exception tce) {
                        tce.printStackTrace();
         * Sets up to easily print HTML documents. It is not necessary to call any of the setter
         * methods as they all have default values, they are provided should you wish to change
         * any of the default values.
         public class HTMLPrinter {
         public int DEFAULT_DPI = 72;
         public float DEFAULT_PAGE_WIDTH_INCH = 8.5f;
         public float DEFAULT_PAGE_HEIGHT_INCH = 11f;
         int x = 100;
         int y = 80;
         GraphicsConfiguration gc;
         PrintService[] services;
         PrintService defaultService;
         DocFlavor flavor;
         PrintRequestAttributeSet attributes;
         Vector pjlListeners = new Vector();
         Vector pjalListeners = new Vector();
         Vector psalListeners = new Vector();
         public HTMLPrinter() {
              gc = null;
              attributes = new HashPrintRequestAttributeSet();
              flavor = null;
              defaultService = PrintServiceLookup.lookupDefaultPrintService();
              services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
              // do something with the supported docflavors
              DocFlavor[] df = defaultService.getSupportedDocFlavors();
              for (int i = 0; i < df.length; i++)
              System.out.println(df.getMimeType() + " " + df[i].getRepresentationClassName());
              // if there is a default service, but no other services
              if (defaultService != null && (services == null || services.length == 0)) {
              services = new PrintService[1];
              services[0] = defaultService;
         * Set the GraphicsConfiguration to display the print dialog on.
         * @param gc a GraphicsConfiguration object
         public void setGraphicsConfiguration(GraphicsConfiguration gc) {
              this.gc = gc;
         public void setServices(PrintService[] services) {
              this.services = services;
         public void setDefaultService(PrintService service) {
              this.defaultService = service;
         public void setDocFlavor(DocFlavor flavor) {
              this.flavor = flavor;
         public void setPrintRequestAttributes(PrintRequestAttributeSet attributes) {
              this.attributes = attributes;
         public void setPrintDialogLocation(int x, int y) {
              this.x = x;
              this.y = y;
         public void addPrintJobListener(PrintJobListener pjl) {
              pjlListeners.addElement(pjl);
         public void removePrintJobListener(PrintJobListener pjl) {
              pjlListeners.removeElement(pjl);
         public void addPrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.addElement(psal);
         public void removePrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.removeElement(psal);
         public boolean printJEditorPane(JEditorPane jep, PrintService ps) {
                   if (ps == null || jep == null) {
                        System.out.println("printJEditorPane: jep or ps is NULL, aborting...");
                        return false;
                   // get the root view of the preview pane
                   View rv = jep.getUI().getRootView(jep);
                   // get the size of the view (hopefully the total size of the page to be printed
                   int x = (int) rv.getPreferredSpan(View.X_AXIS);
                   int y = (int) rv.getPreferredSpan(View.Y_AXIS);
                   // find out if the print has been set to colour mode
                   DocPrintJob dpj = ps.createPrintJob();
                   PrintJobAttributeSet pjas = dpj.getAttributes();
                   // get the DPI and printable area of the page. use default values if not available
                   // use this to get the maximum number of pixels on the vertical axis
                   PrinterResolution pr = (PrinterResolution) pjas.get(PrinterResolution.class);
                   int dpi;
                   float pageX, pageY;
                   if (pr != null)
                        dpi = pr.getFeedResolution(PrinterResolution.DPI);
                   else
                        dpi = DEFAULT_DPI;
                   MediaPrintableArea mpa = (MediaPrintableArea) pjas.get(MediaPrintableArea.class);
                   if (mpa != null) {
                        pageX = mpa.getX(MediaPrintableArea.INCH);
                        pageY = mpa.getX(MediaPrintableArea.INCH);
                   } else {
                        pageX = DEFAULT_PAGE_WIDTH_INCH;
                        pageY = DEFAULT_PAGE_HEIGHT_INCH;
                   int pixelsPerPageY = (int) (dpi * pageY);
                   int pixelsPerPageX = (int) (dpi * pageX);
                   int minY = Math.max(pixelsPerPageY, y);
                   // make colour true if the user has selected colour, and the PrintService can support colour
                   boolean colour = pjas.containsValue(Chromaticity.COLOR);
                   colour = colour & (ps.getAttribute(ColorSupported.class) == ColorSupported.SUPPORTED);
                   // create a BufferedImage to draw on
                   int imgMode;
                   if (colour)
                        imgMode = BufferedImage.TYPE_3BYTE_BGR;
                   else
                        imgMode = BufferedImage.TYPE_BYTE_GRAY;
                   BufferedImage img = new BufferedImage(pixelsPerPageX, minY, imgMode);
                   Graphics myGraphics = img.getGraphics();
                   myGraphics.setClip(0, 0, pixelsPerPageX, minY);
                   myGraphics.setColor(Color.WHITE);
                   myGraphics.fillRect(0, 0, pixelsPerPageX, minY);
                        java.awt.Rectangle rectangle=new java.awt.Rectangle(0,0,pixelsPerPageX, minY);
                   // call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics
                   rv.paint(myGraphics, rectangle);
                   try {
                        // write the image as a JPEG to the ByteArray so it can be printed
                        Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
                        ImageWriter writer = (ImageWriter) writers.next();
                                       // mod: Added the iwparam to create the highest quality image possible
                        ImageWriteParam iwparam = writer.getDefaultWriteParam();
                        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
                        iwparam.setCompressionQuality(1.0f); // highest quality
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        ImageOutputStream ios = ImageIO.createImageOutputStream(out);
                        writer.setOutput(ios);
                        // get the number of pages we need to print this image
                        int imageHeight = img.getHeight();
                        int numberOfPages = (int) Math.ceil(minY / (double) pixelsPerPageY);
                        // print each page
                        for (int i = 0; i < numberOfPages; i++) {
                             int startY = i * pixelsPerPageY;
                             // get a subimage which is exactly the size of one page
                             BufferedImage subImg = img.getSubimage(0, startY, pixelsPerPageX, Math.min(y - startY, pixelsPerPageY));
                                                 // mod: different .write() method to use the iwparam parameter with highest quality compression
                             writer.write(null, new IIOImage(subImg, null, null), iwparam);
                             SimpleDoc sd = new SimpleDoc(out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null);
                             printDocument(sd, ps);
                             // reset the ByteArray so we can start the next page
                             out.reset();
                   } catch (PrintException e) {
                        System.out.println("Error printing document.");
                        e.printStackTrace();
                        return false;
                   } catch (IOException e) {
                        System.out.println("Error creating ImageOutputStream or writing to it.");
                        e.printStackTrace();
                        return false;
                   // uncomment this code and comment out the 'try-catch' block above
                   // to print to a JFrame instead of to the printer
                   /*          JFrame jf = new JFrame();
                             PaintableJPanel jp = new PaintableJPanel();
                             jp.setImage( img );
                             JScrollPane jsp = new JScrollPane( jp );
                             jf.getContentPane().add( jsp );
                             Insets i = jf.getInsets();
                             jf.setBounds( 0, 0, newX, y );
                             jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
                             jf.setVisible( true );*/
                   return true;
              * Print the document to the specified PrintService.
              * This method cannot tell if the printing was successful. You must register
              * a PrintJobListener
              * @return false if no PrintService is selected in the dialog, true otherwise
              public boolean printDocument(Doc doc, PrintService ps) throws PrintException {
                   if (ps == null)
                   return false;
                   addAllPrintServiceAttributeListeners(ps);
                   DocPrintJob dpj = ps.createPrintJob();
                   addAllPrintJobListeners(dpj);
                   dpj.print(doc, attributes);
                   return true;
              public PrintService showPrintDialog() {
                   return ServiceUI.printDialog(gc, x, y, services, defaultService, flavor, attributes);
              private void addAllPrintServiceAttributeListeners(PrintService ps) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < psalListeners.size(); i++) {
                   PrintServiceAttributeListener p = (PrintServiceAttributeListener) psalListeners.get(i);
                   ps.addPrintServiceAttributeListener(p);
              private void addAllPrintJobListeners(DocPrintJob dpj) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < pjlListeners.size(); i++) {
                   PrintJobListener p = (PrintJobListener) pjlListeners.get(i);
                   dpj.addPrintJobListener(p);
              // uncomment this also to print to a JFrame instead of a printer
              /* protected class PaintableJPanel extends JPanel {
                   Image img;
                   protected PaintableJPanel() {
                        super();
                   public void setImage( Image i ) {
                        img = i;
                   public void paint( Graphics g ) {
                        g.drawImage( img, 0, 0, this );
    Thanks
    Ram

    Ram,
    I have had printing problems too a year and a half ago. I used all printing apis of java and I still find that it is something java lacks. Now basically you can try autosense. To check whether your printer is capable of printing the docflavor use this PrintServiceLookup.lookupPrintServices(flavor, aset); . If it lists the printer then he can print the document otherwise he can't. I guess that is why you get the error.
    Regards,
    Kevin

  • Print only a specific control or indicator on a front panel to HTML document

    Is there any way to print a specific control or indicator (not the whole front panel) to HTML document? I am trying to print a report that has a graph and some indicator value on it.

    There is a VI called "Append Control Image to Report.vi" which will allow you to do this. It's located in the Functions>>Report Generation pallette. Take a look at this and see if it's what you're looking for.
    J.R. Allen

  • Photosmart C6180 prints too many copies of PDFs and HTML-documents

    Hi,
    My Photosmart C6180 prints multiple copies of documents even if I haven't asked for it. This seems to only apply to PDFs and HTML-documents, I haven't seen it happen with Word/Excel. It's not consistent, it happens most of the time but now always for these documents. When I look at the console, when it has started printing I see shortly the status "Printing - Restarting". That's probably when it starts the 2nd copy. Sometimes it stops by itself, other times it seems to be looping and I have to turn the printer off and delete the document from the queue.
    HP solution center SW is updated, I run Vista with latest service packs on a Thinkpad T400s.
    Any ideas?
    Thanks!

    My C6180 printed multiple copies of any document from my Vista OS laptop ( wireless connection ), but not from my
    XP OS desktop ( USB connection), even though I selected 1 copy on the print menu. Unchecking "Enable bidirectional support" in the Properties / Ports dialog box solved the problem. Hope this helps someone too.

  • Printer issues for HTML document.

    Hello,
    We are facing a critical problem.In our project we are using sql server 2005,from one of the SP we are generating an HTML document.Ideally this document should be printed in 2 pages.When we print that with Laser JET 2430 printer it gets printed in two pages but when we print that with other version printer it gets printed in four pages.Our client has different version printer due to which they get that document printed in four pages which they want to be in two pages only.
    Workflow of this Document generation is as foloows:
    1)When this SP is executed it generates a HTML document and places at some shared folder.
    2)Then we open the document and apply follwing settings to document in order to view and print it properly as:
    View>>Text Size>>Medium.
    Also check if the size is A4 and margins are set to default values by doing the following.
    Go to
    File>>Page Setup
    Size: A4
    Left: 0.166 Right: 0.166
    Top: 0.166 Bottom: 0.266
    And then click on Print Preview.
    When the document is previwed it should be on two pages only.
    Basically here problem is that document gets printed perfectly when its Top margin is set to 0.166 but each printer has its own minimum Top margin settings due to which in different printers it takes different Top margin values for e.g when we print the document with HP Laser Jet P3005x its minimum Top margin are 0.196 then that document expands to 3 pages.Even we try to set this to 0.166 it gets overwritten with 0.196.
    Can you please tell us what changes should be done to SP which is generating the HTML so that its setting doesnt change printer wise and document gets printed in two pages only.Or else can you please suggest the links of forums where we can discuss this issue.

    Hi
    Quest_RG,
    This is actually very simple question, but it is an CSS question and not sql :-) once you open the HTML document the part of the SQL is over.
    You can use CSS to configure the printing way. using page-break-before and
    page-break-after you can insert CSS breaks where ever you want. for example:
    content here
    <DIV style="page-break-after:always"></DIV>
    content here
    I Hope this will help you,
    [Personal Site] [Blog] [Facebook]

  • Print HTML Report.vi doesn't scale properly.

    LV 8.5.1, Report Generation Toolkit, XP.  Our application uses the Print HTML Report.vi to print an HTML report.
    We found that on some installations the resulting page does not scale properly.  Instead of being one page wide,
    the printout is about 1.5 pages wide (and proportionately longer), leading to our report being truncated.
    Tried different printers, different print drivers, no difference.
    Finally we noticed that the affected computers all had Internet Explorer 6 installed.  Updating to Internet
    Explorer 7 fixed the problem.  Don't know about IE8, I expect that will work as well.
    Hopefully this will help someone else who runs across this problem.  I couldn't find any reference to
    an IE > 6 dependency in the Report Generation Toolkit readme system requirement.
    Matt

    Hi Charlie,
    The layout option is not wired to anything in the Standard, HTML, Excel and Word Report, but it is used in the Quick Print default case.  The Help document for this VI mentions that the layout option is ignored on Standard and HTML Reports but does not mention the Excel or Word Reports.
    This was discovered a little while ago in this discussion forum.  And a report has be filed to R&D by Ben.
    Justin Parker
    National Instruments
    Product Support Engineer

  • Print HTML Report Automatica​lly after Each UUT

    Hello
    I saw the document on NI site called "Print HTML Report Automatically after Each UUT". That's exactly what I want to do with XML files. So I put it in my sequence file and it works fine, but when it opens the xml file at the first step, there's a pop-up from IE who say that "Scripts are generally safe, do you want to authorise this script" (This message is also displayed when I open my file in files explorer).
    So, the print is not automatically anymore as I must answer to this pop-up. does anybody has a solution to bypass this pop-up ?
    I tried to use the property silent on the class IWebBrowser2. Inded, the pop-up doesn't appear anymore, but my XML file isn't correctly printed. I supposed the default response of the pop-up (which is no) is applied. So the script isn't executed.
    I also tried to configure IE to not display this pop-up : No result
    Regards
    Laurent

    Hello,
    I think that you need to configure your browser, can you take a look a this article:
    http://www.maxi-pedia.com/scripts+are+usually+safe​+do+you+want+to+allow+scripts+to+run
    Regards,
    Nacer M. | Certified LabVIEW Architecte

  • Print HTML doument without open it from an applet

    I need to know how I can print an HTML document from an applet developed with Jbuilder 4. I'm not a very expert developer and I need a detailed information about this problem. Important is that the HTML document is printed without open it.
    I use: win 2000 pro
    J2RE 1.4.0
    thanks in advance for your help
    Mauro Losa

    Thanks for your help but my problem is that i want print the document without display it.
    I think to have find a solution using Java Print Service API (JDK 1.4) but when i run the example the system display this error refered to this instruction
    "PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);":
    java.lang.UnsatisfiedLinkError: getDefaultPrinterName
    at sun.print.Win32PrintServiceLookup.getDefaultPrinterName(Native Method)
    at sun.print.Win32PrintServiceLookup.getDefaultPrintService(Unknown Source)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Unknown Source)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Unknown Source)
    at javax.print.PrintServiceLookup.getServices(Unknown Source)
    at javax.print.PrintServiceLookup.lookupPrintServices(Unknown Source)
    at untitled4.applet1.main(Applet1.java:32)

  • How to print html file on client system without viewing data on client syst

    I want to print html data from database.
    i am not able to print it using java code,
    javascript can do that.
    but in javascript window is opened on client browser.
    but i dont want to open that
    var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
           disp_setting+="scrollbars=no,width=0,height=0";
         var docprint = window.open("","",disp_setting);
         //docprint = new PopUpWindow() ;
         docprint.document.write('<%= mm %>');
         docprint.document.close();
            docprint.focus();
         docprint.document = null; mm contents the data to be printed. it prints well but window is shown
    in mm there is <BODY self.print() > so it prints on printer but i am viewing window i donot want to view window....
    and print Dialog box also.. I want to by pass this both.
    please send me code or any help regarding that.
    ....

    1. Post a javascript question on a javascript forum please.
    2. Don't think you can bypass without some plugin/setting on the client browser.

  • Print html report with waveform

    I'm trying to make a report on my system using print from the File menu, and then saving the report as a html document. However, I don't seem to get the descriptions for waveforms in the report.
    I've tried on both WIN-NT and WIN-2000 machines, but still no description.
    Would also want to know if it is possible not to include descriptions of parts of clusters (such as waveforms or error clusters), but instead just include the description of the cluster itself.

    > Unfortunately, what you see in the Print window is all the options
    > available. You can print description for only the icon, for all
    > controls, or for connected controls. You cannot select to print
    > description of only few controls. However, I tested this and was able
    > to print description for a waveform chart.
    > You can suggest this additional feature if you go to ni.com, click on
    > "Contact NI" in the top right corner, and then select "feedback" under
    > Product Feedback.
    In the meantime, you can use the report generation VIs to make a custom
    report. Use a property node to read the description and add it wherever
    you like.
    Greg McKaskle

Maybe you are looking for