Print HTML in Landscape

Hello,
I have rendered my HTML on a JEditorPane with Editable set to false. The pages are displayed fine on the screen. However, when I try to print I have a problem. If I print in Portrait, everything prints just fine (only everything doesn't fit on the page). However, if I switch to Landscape (which should be an easy switch--pf.setOrientation(PageFormat.LANDSCAPE)), only the background of my tables prints on the page. Any ideas on this?
  public void printReport() {
      JFrame frame = new JFrame("Test");
            JPanel allPages = new JPanel();
            allPages.setLayout(new GridLayout(0,1));
            for (int i=0; i<pages.size(); i++) {
                ((ReportPageHTML)pages.elementAt(i)).setPreferredSize(new Dimension(725,554));
                ((ReportPageHTML)pages.elementAt(i)).setMinimumSize(new Dimension(725,554));
                 allPages.add((ReportPageHTML)pages.elementAt(i));
                ((ReportPageHTML)pages.elementAt(i)).addPageNumber(i+1,pages.size());
                ((ReportPageHTML)pages.elementAt(i)).setText();
            } //for
            JScrollPane scrollPane = new JScrollPane(allPages);
            frame.getContentPane().add(scrollPane);
           scrollPane.setPreferredSize(new Dimension(300,100));
           frame.setSize(600,400);
           frame.setVisible(true);
           frame.setState(JFrame.ICONIFIED);
        PrinterJob printJob = PrinterJob.getPrinterJob();
        PageFormat pf = printJob.defaultPage();
        pf.setOrientation(PageFormat.LANDSCAPE);
        double smallMargin = .4 * 72;
        Paper paper = pf.getPaper();
        paper.setImageableArea(smallMargin,smallMargin,(paper.getWidth() - (2*smallMargin)),(paper.getHeight()-(2*smallMargin)));
        pf.setPaper(paper);
        Book book = new Book();
        for (int i = 0; i < pages.size(); i++) {
            book.append((Printable)pages.elementAt(i),pf);
        printJob.setPageable(book);
     if(printJob.printDialog()) {
            try {
                printJob.print();
            } catch (Exception e) {System.out.println("Print Exception " + e); }
       frame.dispose();
    }//printReport()
  

Hi!
Your code looks a bit to difficult i think...
I think it would be much easier, if your writing a class, wich Prints out the whole JEditorPane.
- create a new class thats implements Printable
- int the constructor you give the class your JEditorPane and save it in the class
MyEdPanePrint(JEditorPane ep) {
this.ep = ep;
- write the      
public int print(Graphics g, PageFormat pf, int page)with:
-set the Pane undouble-buffered
-set the size (fixed size, or depending on pageformat pf);
-set it visible
-scale it, if you wanna change the resolution of the paper
-transform your GraphicsContextDevice
-print your JEditorPane
this is the standard way of printing as i would say.
It's easier and better to understand than your to print..
kind regards

Similar Messages

  • Printer Setup for HTML reports (Landscape)

    I'm trying to print an HTML report in Landscape, the Report Orientation VI only works with Standard Reports, and I can't find anything that will let me modify the "Printer Setup"
    Anyone done this?

    Jeff,
    To print an HTML report it first has to be rendered. To render HTML, you need a browser. For example, you can render HTML in either Internet Explorer or Firefox or Opera, and all three might render the same data slightly differently. To simplify the situation let's say that you're using IE. Once IE renders the HTML, you then have to get it to send the rendered output to the printer. So you can see why it isn't time or cost-effective for NI to try and necessarily support these functions. For the end user however, I'd guess that quite a few people have had this problem.
    I have had to do a lot of digging around to get HTML reports to print right. My solution has been to use an ActiveX container with an IWebBrowser2 object (Internet Explorer). This will let you load and print HTML reports programatically however (glancing back over some old code) I don't see immediately how you can print a report in Landscape. With an ActiveX container however you can call the IE print preview function which will let you (the user) modify the report printing to Landscape. It's not a programmatic solution since you have to interact with the GUI but it works. Also, once you set the setting to Landscape, everything printed afterwards using your ActiveX container will also print in Landscape.
    Something else which may not apply to you (but maybe--I'll at least mention it) is printing a landscape single image... that's usually why I needed to print landscape... to print out a full page screenshot of a graph or something. I do this in portrait mode by just attaching the control image but rotating it first and adding the HTML code to make it 100% of the vertical page.
    Last but not least, if you are 100% set on using a programmatic implementation to print a landscaped report (no user interaction), the best thing to do would be to build on an ActiveX implementation so that your report is being loaded and printed from an embedded IWebBrowser2 object. With the IWebBrowser2 object there is an option for using a pre-defined print template. This option is NOT for the faint of heart and requires you basically to re-program the whole IE print-preview functionality. However, it's not impossible either, it just takes the time of learning basically how the IE print preview interface works and then adapting it to your application (in this case, landscaped printouts). This is also the ONLY way to change HTML report headers and footers. The print preview interface in IE is written entirely in javascript--you can get details on msdn (search for "print preview templates"). However, there isn't really enough info there to do things with any ease. So....
    If you get to the point where you get an ActiveX container working and want to fool with the IE print preview javascript templates, let me know. I have extracted the entire template and associated images from the windows DLL it is stored in so I could adapt it and change the headers and footers for my reports and things of that nature.
    Now that I mention it, I believe that is the only way also to actually set landscape or portrait--by programmatically changing the printing margins (so it prints 11x8.5 instead of vice versa).
    Anyway, hope that helps...

  • How to print HTML to a remote Server

    Ho guys my problem is only this
    how to print HTML to a remote Server
    i hav used JavaPrintService for it javax.print....
    The Doc Flavor i used is
    DocFlavor.INPUT_STREAM_TEXT_HTML_HOST;
    and with simple print attribute set but it doesnt locates
    the PrintSerivces.
    Plz try this code on your system(Jdk1.4 beta) and see whether it detects PrintServices or not
    import java.io.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import javax.print.event.*;
    public class PrintHTML {
    FileReader readfile;
    Doc doc;
         public static void main(String args[]) {
              PrintHTML ps = new PrintHTML();
         public PrintHTML() {
              DocFlavor flavor =DocFlavor.INPUT_STREAM_TEXT_HTML_HOST;
              PrintRequestAttributeSet aset =
                   new HashPrintRequestAttributeSet();
              aset.add(MediaSizeName.ISO_A4);
              // aset.add(OrientationRequested.LANDSCAPE);
              aset.add(new Copies(1));
    PrintService[] pservices =
                   PrintServiceLookup.lookupPrintServices(flavor, aset);
    if (pservices.length > 0) {
                   System.out.println("Available printer " + pservices[0].getName());
                   System.out.println("Available printer " + pservices[1].getName());     
                   System.out.println("Available printer " + pservices[2].getName());     

    The documentation is misleading. You cannot directly print HTML. See:
    http://developer.java.sun.com/developer/bugParade/bugs/4495770.html

  • 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

  • Problem with NIReport.llb\Print HTML Report using IE.vi on different machines

    We have 5 machines here in our workgroup which have the same state regarding security patches and other system updates. We recently found out that there is a problem with the NIReport.llb\Print HTML Report using IE.vi on the different machines.
    If I would open the VI on MachineA the control could be loaded. If I would open the VI on MachineB the control could be loaded. If I would copy the VI from MachineB to MachineA and open the VI the control could not be loaded. If I would copy the VI from MachineA to MachineB and open the VI on MachineB the control could be loaded. MachineB could load the version from MachineA and MachineB but on MachineA only the own version will load. I have seen that both versions have the same GUID for the Microsoft Webbrowser but are different in some other aereas.
    Since printing HTML Reports is part of the application which will be distributed as application I want to know if someone else have seen such a behaviour or has got problems distributing an application.
    Also I want to know which additional information is stored in an Active-X container about the control beside the GUID.
    We have Win XP Prof SP2 with MS IE 6.0.2900.2180 on all machines in the workgroup.
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

    Hi Tom,
    this is the VI <vi.lib>\Utillitiy\NIReport.llb\Print HTML Report using IE.vi copied from a machine that can load and run the VI and it will print. On this machine the control in the VI is white.
    This VI will give the "Control could not be loaded" message on my machine.
    The file shdocvw.dll is 2006-10-23 16:18 size 1.460 KB and I verifyed that both machines have the same version of this file.
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions
    Attachments:
    Print HTML Report using IE.png ‏11 KB

  • 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 FILE

    Hi all :
    I save a HTML FILE ,, I want to print this file from labview ,, how can I do that
    thanks

    Hi Mike :
    Sorry that I am asking so lot ,, but I don,t know how to Change "Print HTML Report.vi" in the same way and save it with a new name. i am using labview 8.5 I don,t see "print HTML Report.vi", I have "print report.vi "only
    Who  can I change it  ?? can you explain or send 
    thank alot 

  • 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

  • Print html file via share intent

    Hello HP
    I'm a developer, I trying to print html file to HP Printer via share intent. Here is my code:
    Intent intent = new Intent("org.androidprinting.intent.action.PRINT");
    Uri uri = Uri.parse(path);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "ePrintWebContent/*");
    startActivity(intent);
    Nothing happen when I share this intent. Please show me right way to print html file.
    Thank you!!

    Did you look in the LabVIEW Help? http://zone.ni.com/reference/en-XX/help/371361G-01​/lvhowto/reg_hndl_ax_evnts/
    You right-click on that parameter and select Create Callback VI. This will automatically create a VI with the required inputs and outputs. This is the VI that will be called when the event occurs. If you need the callback VI to update any front panel controls of the main VI, then you can pass in control references via the User Parameter input.
    Attached is a modification of the shipping example that handles the Navigate and DocumentComplete events.
    Attachments:
    Navigate Callback Example.vi ‏24 KB
    Navigate Callback.vi ‏15 KB
    DocumentComplete Callback.vi ‏15 KB

  • Print html file with barcode from abap report

    hi
    i am printing html file from abap program using gui_execute.
    i am using netscape.exe , its printing first time and when reprint its not working
    basically html file contains gif file which has fedex barcode.
    could you please let me know how to print html file from report

    DGU wrote:
    where to check RAW or TEXT? the print report vi only asks for file name and printer name.
    When I print from notepad, everything just goes by default. This is a label printer, so I never need to specify printing parameter such as size, orientation, etc in the past
    Famous last words go something like this: "...never had to do that before."  Maybe you have to do that now.  It's worth at least comparing the defaults settings for bothe generic drivers.  It could save you a lot of headache if you notice something different.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Print Html page Using Java

    I need to print Html Page into my printer, how can I do this. Any help will be appreciated.
    Wil

    File > Print.
    See: http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/printing2d.fm.html
    And:
    http://java.sun.com/j2se/1.4.2/docs/guide/jps/index.html
    And google "Java JPS"

  • Can I specify font size=1 when printing HTML?

    I want print my HTML report in font size = 1. I don't know how to do it?
    When using report builder, there seems no special control for printing HTML?
    Hope experts here broaden my mind
    Richard

    This is possible
    1) In Builder paper layout select the object for which you want to change the font size
    2) In menu
    Format --> Font
    You can change the font and its size
    Then generate to html/htmlcss . I have verified this
    Thanks
    The Oracle Reports Team

  • Error according printing html report

    I bulid a vi to print HTML report but I have problem printing this report .
    I try ever to used some example which national Instrument bulid , such as Report Generation > Text
    Report, but ever in this example I couldn't print the file (HTML).

    Wisam,
    Could you tell us what procedure are you following to run that example? and also what version of LabVIEW you have?
    The way you have to run that example (Text Report.vi) is that when you open it, in the control that reads: "Report Type" you select HTML, and also in the control that reads "HTML Save Path" you set the path like for example "C:\test1.htm", now run it and you should have now the HTML format type report. I believe that you also have in that same directory of examples another one called : Example HTML Report Report, that one also shows how to print a report to an HTML file. Try the example you mention setting up the controls that I wrote above and it should work. If not please contact us and we can try to send you an original example and see if i
    t works. You can do it by this same means or by direct contact ( www.ni.com/ask ).
    Good luck!...
    Nestor Sanchez
    Applications Engineer
    National Instruments
    Nestor
    National Instruments

  • Unable to print HTML pages

    After a good bit of reading, I found that printing HTML directly to the printer doesn't work for many printers. I don't want to print the code. I want the actual HTML page. I have some code here that reads the HTML file into a JEditorPane and then is rendered into a graphic for printing.
    My code compiles fine, I'm not getting any errors, but what I'm also not getting is any pages printing.
    Here is the source of my class:
    * PrintReport.java
    * @author tristan
    * Created on September 27, 2007, 4:06 PM
    package fedex;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import java.io.*;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.ServiceUI;
    import javax.print.SimpleDoc;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import javax.swing.JEditorPane;
    import javax.swing.RepaintManager;
    public class PrintReport
        private FileInputStream fileIS;
        private Doc doc;
        private DocAttributeSet das = new HashDocAttributeSet ();
        PrintService defaultService;
        /** Creates a new instance of PrintReport */
        public PrintReport ()
        public void printHTMLFile (String file) throws FileNotFoundException, IOException
            PrintableEditorPane jEditorPane = new PrintableEditorPane ();
            jEditorPane.setContentType ("text/html");
            jEditorPane.read (new BufferedInputStream (new FileInputStream (file)), "");
            System.out.println (jEditorPane.getText ());
            PrinterJob job = PrinterJob.getPrinterJob ();
            job.setPrintable (jEditorPane);
            if (job.printDialog ())
                try
                    job.print ();
                catch (Exception ex)
                    System.out.println (ex);
        public class PrintableEditorPane extends JEditorPane implements Printable, Serializable
            public int print (Graphics g, PageFormat pf, int pageIndex) throws PrinterException
                Graphics2D g2 = (Graphics2D)g;
                g2.setColor (Color.black);
                RepaintManager.currentManager (this).setDoubleBufferingEnabled (false);
                Dimension d = this.getSize ();
                double panelWidth = d.width;
                double panelHeight = d.height;
                double pageWidth = pf.getImageableWidth ();
                double pageHeight = pf.getImageableHeight ();
                double scale = pageWidth / panelWidth;
                int totalNumPages = (int)Math.ceil (scale * panelHeight / pageHeight);
                System.out.println ("Total pages to print are " + totalNumPages);
                if (pageIndex >= totalNumPages) return Printable.NO_SUCH_PAGE;
                g2.translate (pf.getImageableX (), pf.getImageableY ());
                g2.translate (0f, -pageIndex * pageHeight);
                g2.scale (scale, scale);
                this.paint (g2);
                return Printable.PAGE_EXISTS;
    }I tried using a complex HTML file as well as a basic one, but everytime Total pages to print are 0 is printed back to the console. I can't figure out why it's unable to create any pages to print.

    DrClap wrote:
    I think you will find thatDimension d = this.getSize ();produces (0, 0) until you actually display your component somewhere. I believe it's possible to "display" it in such a way that it doesn't appear on the user's screen, but I don't know how.
    There's a Swing forum here where you get answers from people who are good at Swing. Posting here attracts answers from people like me who are mediocre at it.I think that calling validate() on a Container will lay it out and size it's components, even if it hasn't been made visible, but don't take my word for it.

Maybe you are looking for