Java 6  JEditorPane.print pagination

I now see that Java 6 has a print() function for JEditorPane. My question is does this method do some sort of pagination so that a line of text will not be split between two pages? Does anyone have experience with this method yet?

What do you expect to see if you print a single sentence that is too long to be contained on one page?
Since there has to be some kind of pagination control in the method, either do some experimenting or take a look at the method's source code - it should be in src.zip in your JDK directory.

Similar Messages

  • Printing a PDF document using Java 1.4 Printing API

    Hi,
    When I tried to print a PDF document using JAVA 1.4 Printing API, I got the following exception.
    Exception in thread "main" sun.print.PrintJobFlavorException: invalid flavor
    at sun.print.Win32PrintJob.print(Win32PrintJob.java:290)
    at Printing.main(Printing.java:40)
    I am able to print the same PDF document using Acrobat reader.
    Is PDF format not supported in JAVA 1.4 printing API? or is something wrong in my code?
    here is the sample JAVA program that I was using
    import javax.print.*;
    import javax.print.attribute.*;
    import java.io.*;
    public class Printing {
    public static void main(String args[]) throws Exception {
    String filename = args[0];
    PrintRequestAttributeSet pras =
    new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    PrintService defaultService =
    PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
    System.exit(0);
    Thank you
    Sumana

    Here's a pure Java solution (that works!):
    http://www.mycgiserver.com/~zhouwu/pdf/readme.html
    The caveats are:
    - prints only to the default printer
    - requires a properties file located in the home directory
    my workaround for the last:
         * Print a PDF file to the default printer (might consume lots of memory!).
         * <p>
         * <b>Required:</b>
         * <ul>
         * <li>a file "acrobat.properties" needs to be in the working directory. The content is:
    <table align="center" bgcolor="#E0E0E0" border=1 cellpadding="10" cellspacing="0"><tr><td><pre style="margin-top:0; margin-bottom:0">
    #com.adobe.acrobat.Viewer Properties
    #Wed Oct 29 20:34:05 PST 2003
    com.adobe.acrobat.AcceptedLicAgreement=true
    com.adobe.acrobat.Fax_Fine_Mode=true
    com.adobe.acrobat.Find\:FindAll=false
    com.adobe.acrobat.Find\:FindBackwards=false
    com.adobe.acrobat.Find\:FindWholeWord=false
    com.adobe.acrobat.Find\:MatchCase=false
    com.adobe.acrobat.Open_Dialog_Directory=C\:\\temp\\
    com.adobe.acrobat.Open_Dialog_File=itext.pdf
    com.adobe.acrobat.Print_Method_Known=true
    com.adobe.acrobat.Shrink_To_Fit=false
    com.adobe.acrobat.SitePreferencesURL=file\://localhost/C\:/pdf/acrobat-site.properties
    com.adobe.acrobat.Use_Print_Server=false
    com.adobe.acrobat.util.fontDirectories=C\:\\Winnt\\Fonts
    com.adobe.acrobat.util.fontIgnoreExtensions=.fon;.pfm;.ini;.lst;.txt;.doc;.ttmap;.z;.enc;.dir;.afm;.f3b;.pfa;.spd;.ps;.bepf;.map;.alias;.scale;.all;.upr
    </pre></td></tr></table>
         * <li>The JAR files PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip in the CLASSPATH.
         * </ul>
         * <p>
         * Note: the file "acrobat.properties" is expected to be in the user's home directory. As this is not always feasible,
         * the system property "user.home" is mapped to "user.dir" for the time of execution.
         * @param fileName Name of PDF file to print.
         * @throws Exception on error.
         * @see <a href="http://www.mycgiserver.com/~zhouwu/pdf/readme.html">PDF Server (Silent) Printing</a>
        public void printPDF(String fileName) throws Exception {
            String oldHome = System.getProperty("user.home");
            System.setProperty("user.home", System.getProperty("user.dir"));
            PDFPrinter vi = new PDFPrinter();
            vi.activate();
            vi.setDocumentInputStream(new FileInputStream(fileName));
            vi.printAll();
            System.setProperty("user.home", oldHome);
        }//printPDF()I just need the following additional files in my CLASSPATH: PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip. Despite the note at the site above that "printing quality is not very good", i can't agree: the print quality is quite good. Not perfect, but acceptable for most uses.
    (Tested on Windows 2000 SP4, J2SE 1.4.2_03, hp laserjet 2300dn)

  • HT5243 Issue with Java operation on printer operation using Shipping software.

    We are running a shipping system from APC couriers using the online booking system, there system runs using Java for the printing but it will not print normally due to a Java issue so has to be printed from another screen, our system has the latest version of Java any suggestions

    4 x 146.8Gb local disks RAID 5 mirrored using the hardware raid controller HP Smart Array 5i+.
    2 Emulex LP10000 HBA cards dual path connected to EMC Symmetrix and IBM DS4800 SAN Storage. There's your problem right there.
    In almost every situation I've encountered as a DBA, RAID5 is slow. Slower than single disk. If you have 4 drives, you're better off doing a RAID10 so that your hardware doesn't have to compute the parity bit. You'll lose 145GB, but you're MUCH better off in terms of performance. RAID5 was meant for file servers and low-load webservers, not high-end databases.
    The only time I've ever seen RAID5 perform acceptably was when we had redo, rollback and the default tablespaces on a different set of disks, and the main data tablespaces on a RAID5. There were very few updates/inserts to the main tablespaces and mostly reads. That's the only time you can use RAID5. But I'd still suggest doing RAID10 and just putting everything on it.
    In general, I also have NOT seen good performance with a SAN. The only time you should use a SAN is when you can't get the capacity you need onto a SCSI channel (or, again, you don't need it to be fast). Otherwise go internal disks on a RAID10 and forget about the SAN. SANs have the disadvantage of having to be shared with a large number of hosts to be cost-effective and shared IO isn't something you want on a high-end database.
    For more information, check this out:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:3322095211375936281::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:359617936136

  • JEditorPane printing a HTML PAGE

    Hi,
    Here is my problem. I am displaying a HTML Page in a JEditorPane. So far so good.
    when I try to print is printing to my printer. Here is the problem the Text or to say the font doesnot look good in the paper, each letter is not nice and smoth and it looks like some of the pixels in each letter were lost. This happens right when I initialize the JEditorPane with html code. I can also see the pixels in each letter are lost when I initilized it in a JEditorPane.
    Any help will be appreciate.

    How are you printing? Are you using the Printing API?
    You can try antialiasing the text before printing:
    http://www.exampledepot.com/egs/java.awt/AntiAlias.html

  • Again on JEditorPane printing, please help me

    Hi everybody,
    first of all excuse me if I write again about an already discussed topic,
    but I still haven't found a good solution for it.
    I have a JEditorPane that I use to render HTML documents, and I need
    to be able to print the contents.
    I then created my PrintableEditorPane class that implements Printable
    add the following print() method:
    public int print(Graphics g, PageFormat fmt, int index) throws PrinterException
            Graphics2D g2d = (Graphics2D) g;
            // Set default foreground color to black
            g2d.setColor(Color.black);
            // For faster printing, turn off double buffering
            RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
            // Get size of document
            Dimension d = getSize();
            double panelWidth = d.width; // Width in pixels
            double panelHeight = d.height; // Height in pixels
            double pageWidth = fmt.getImageableWidth(); // Width of printer page
            double pageHeight = fmt.getImageableHeight(); // Height of printer page
            int totalNumPages = (int) Math.ceil(panelHeight / pageHeight);
            // Make sure not print empty pages
            if (index >= totalNumPages)
                return Printable.NO_SUCH_PAGE;
            // Shift Graphic to line up with beginning of print-imageable region
            g2d.translate(fmt.getImageableX(), fmt.getImageableY());
            // Shift Graphic to line up with beginning of next page to print
            g2d.translate(0f, -index * pageHeight);
            // Repaint the page for printing
            paint(g2d);
            return Printable.PAGE_EXISTS;
    }Everything works quite fine, with the exception that if text spans on
    multiple pages, it can happen that the bottom part of the last line in
    a page is printed in the next one.
    I found that this topic occurs rather frequently in the forum, so I changed
    the code with the following one, taken from the Internet:
    public int print(Graphics g, PageFormat fmt, int index) throws PrinterException
            Graphics2D g2d = (Graphics2D) g;
            // Set default foreground color to black
            g2d.setColor(Color.black);
            // For faster printing, turn off double buffering
            RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
            // Shift Graphic to line up with beginning of print-imageable region
            g2d.translate(fmt.getImageableX(), fmt.getImageableY());
            View rootView = getUI().getRootView(this);
            if (index > currentPage)
                currentPage = index;
                pageStartY += pageEndY;
                pageEndY = g2d.getClipBounds().getHeight();
            g2d.translate(g2d.getClipBounds().getX(), g2d.getClipBounds().getY());
            Rectangle allocation = new Rectangle(0, (int) -pageStartY, getWidth(), getHeight());
            if (printView(g2d, allocation, rootView))
                return Printable.PAGE_EXISTS;
            else          
                currentPage = -1;
                pageStartY = 0.0;
                pageEndY = 0.0;
                return Printable.NO_SUCH_PAGE;
    protected boolean printView(Graphics2D g2d, Shape alloc, View view)
            boolean pageExists = false;
            Rectangle clip = g2d.getClipBounds();
            Shape childAlloc;
            View childView;
            if (view.getViewCount() > 0)
                for (int i = 0; i < view.getViewCount(); i++)
                    childAlloc = view.getChildAllocation(i, alloc);
                    if (childAlloc != null)
                        childView = view.getView(i);
                        if (printView(g2d, childAlloc, childView))
                            pageExists = true;
            else
    //  I
                if (alloc.getBounds().getMaxY() >= clip.getY())
                    pageExists = true;
    //  II
                    if ((alloc.getBounds().getHeight() > clip.getHeight()) && (alloc.intersects(clip)))
                        System.out.println("Calling view.paint()... (1)");
                        view.paint(g2d, alloc);
                    else
    //  III
                        if (alloc.getBounds().getY() >= clip.getY())
                            if (alloc.getBounds().getMaxY() <= clip.getMaxY())
                                System.out.println("Calling view.paint()... (2)");
                                System.out.println(view.getClass().getName());
                                System.out.println(view.getElement().getName());
                                view.paint(g2d, alloc);
                            else
    //  IV
                                if (alloc.getBounds().getY() < pageEndY)
                                    pageEndY = alloc.getBounds().getY();
            return pageExists;
    } Now pagination is handled correctly, but a new problem arises: table
    borders are not printed at all, and this topic too is not new in the forum.
    So I made some investigations that you can see from the println() in the
    code and I found out that all the views are of class InlineView, that is returned
    from HTMLEditorKit when an element with name "content" is found.
    Now the real questions: why don't I get the real views hierarchy of the HTML
    document, and how can I solve my problem?
    Many thanks to anyone who will like to help me.
    Matteo.

    Hello, and thanks for all the great help so far in this thread! I have implemented the above code, and it seems to work great, except for one thing. It always prints the first page twice. My print method is exactly as listed above. Here is my printView method:
    protected boolean printView(Graphics2D g2d, Shape alloc, View view)
                   boolean pageExists = false;
                   Rectangle clip = g2d.getClipBounds();
                   Shape childAlloc;
                   View childView;
                   //System.out.println("View name = " + view.getElement().getName());
                   if (view.getViewCount() > 0 && !view.getElement().getName().equalsIgnoreCase("td"))
                        for (int i = 0; i < view.getViewCount(); i++)
                             childAlloc = view.getChildAllocation(i, alloc);
                             if (childAlloc != null)
                                  childView = view.getView(i);
                                  if (printView(g2d, childAlloc, childView))
                                       pageExists = true;
                   else
    //          I
                        if (alloc.getBounds().getMaxY() >= clip.getY())
                             pageExists = true;
    //          II
                             if ((alloc.getBounds().getHeight() > clip.getHeight()) && (alloc.intersects(clip)))
                             //     System.out.println("Calling view.paint()... (1)");
                                  view.paint(g2d, alloc);
                             else
    //          III
                                  if (alloc.getBounds().getY() >= clip.getY())
                                       if (alloc.getBounds().getMaxY() <= clip.getMaxY())
                                  //          System.out.println("Calling view.paint()... (2)");
                                  //          System.out.println(view.getClass().getName());
                                  //          System.out.println(view.getElement().getName());
                                            view.paint(g2d, alloc);
                                       else
    //          IV
                                            if (alloc.getBounds().getY() < pageEndY)
                                                 pageEndY = alloc.getBounds().getY();
                   return pageExists;
         }Can anyone see why it would print the first page twice every time?
    Thanks for you help!

  • Bug: Java applet cannot print, even with print permission granted.

    I was not able to file this bug report at the official Apple bug report site, so...
    Summary:
    When a java applet initiates a print job, the user is (correctly) presented with a dialog requesting permission for printing. Once permission is granted, the printing subsystem attempts to communicate with CUPS at localhost:631, and permission is denied. To the naive user, it appears that the applet is broken.
    Steps to Reproduce:
    Go to
    http://www.wordle.net/gallery/wrdl/921427/WordleCore_SourceCode
    Once the applet has loaded, click the button labelled "Print...".
    Expected Results:
    After permitting printing, the user should see the print dialog, and printing should proceed as normal.
    Actual Results:
    Here is the relevant section of the stack trace generated when this happens:
    <pre>java.security.AccessControlException: access denied
    (java.net.SocketPermission localhost:631 connect,resolve)
    at java.security.AccessControlContext.checkPermission
    (AccessControlContext.java:264)
    at java.security.AccessController.checkPermission
    (AccessController.java:427)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:
    532)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:521)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:231)
    at sun.net.www.http.HttpClient.New(HttpClient.java:304)
    at sun.net.www.http.HttpClient.New(HttpClient.java:321)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient
    (HttpURLConnection.java:813)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect
    (HttpURLConnection.java:765)
    at sun.net.www.protocol.http.HttpURLConnection.connect
    (HttpURLConnection.java:690)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream
    (HttpURLConnection.java:857)
    at sun.print.IPPPrintService.opGetAttributes(IPPPrintService.java:
    1419) </pre>
    Regression:
    This problem was introduced only with the most recent Java update.
    Notes:
    There is no workaround for the applet author, other than to use a signed applet, which is prohibitively expensive, and which should not be required for printing, anyway. It's difficult to instruct the user in how to grant the appropriate permissions via policy files, since the finder will not allow a user to create a file named ".java.policy" in their home directory, and since the system policy file is write-protected.

    Jonathan Feinberg wrote:
    I was not able to file a bug report
    You should file a bug report with Apple at http://bugreport.apple.com if you have a developer account or at http://www.apple.com/feedback/macosx.html if you do not have a developer account.
    Good luck w/your issue and please update this thread if you encounter a solution.

  • JDK 1.4.2 java applet image printing on mac safari

    Hi there,
    I'm trying to implement printing inside java applet using javax.print package. I read an article somewhere about the package not working perfectly under mac, and a workaround is to use the old java.awt.print to get the print services, then use the DocPrintJob to print.
    The SimpleDoc I use for capturing the image that I need to print works fine, and the printServices are there. The problem I have is it's giving me an 'invalid flavor' exception when clicking 'Print' on popup PrintDialog.
    It seems that the mimetype is what's causing the problem, as the printer's supported mime type is "application/x-java-jvm-local-objectref". (note that, on PC the printing works fine, with Doc flavor mimetype as image/png and the image I need to print in png format). I tried switching the flavor to SERVICE_FORMATTED.RENDERABLE_IMAGE, printing an ImageDoc class which implements Doc and RenderableImage, but 'invalid flavor' exception still occurs.
    I don't know much about printers on Mac, so I'm not sure what I can do about it, is it something that can be controlled from the Applet or it's something that the user has to set in the system - the Applet can only warn the user and tell the user to do the configuration.
    Thanks in advance!

    SwingUtilities.updateComponentTreeUI() works by first updating the UI of the given component, and then updating the component's children (and their children). So first it will update the JToolBar's UI (which installs the appropriate borders on its buttons), and then it will update each button's UI (which subsequently installs its own default border onto the button, undoing JToolBar's border installation, thanks to the bug mentioned previously).
    Another possible work-around for this problem would be to write your own updateComponentTreeUI() method that updates the child components' UI's before updating the parent component's UI:public static void newUpdateComponentTreeUI(Component c)
         updateTreeUIs(c);
         c.invalidate();
         c.validate();
         c.repaint();
    private static void updateTreeUIs(Component c)
         Component[] children = null;
         if (c instanceof JMenu) children = ((JMenu)c).getMenuComponents();
         else if (c instanceof Container) children = ((Container)c).getComponents();
         // Children first...
         for (int i=0; children != null && i < children.length; i++)
              updateTreeUIs(children);
         // Parent last...
         if (c instanceof JComponent) ((JComponent)c).updateUI();
    }Not sure if this will present any other conflicts though.

  • Looking for java script to print slide

    Hey everyone,
    The print widget and playbar print don't always work too well. Does anyone have a java script they are willing to share with me that will print a single slide and/or a set of slides?
    Thanks!
      Lori

    Hi Lori
    I think it may depend on your browser. If the browser is Microsoft Internet Explorer, sometimes you have make adjustments to coax something like a Flash file to print. You might try clicking File > Page setup... and see if you have the option for printing Background Colors and Images.
    Cheers... Rick

  • Do you need a Java Engine to print W-2?

    We are in the process of upgrading our system to ERP 2005 ... in testing, the HR department said they can't print W-2 because the Java engine wasn't installed.  Can anyone confirm the java engine is a requirment for W2s to be printed in ERP2005?
    Thanks in Advance!

    Hi Dawn.  We tried doing that when we first ran into this problem a few months ago.  It does allow us to print the sapscript forms, but we would still have the issue of the sapscript no longer being supported by SAP for ERP2005.  So if we were to have problems with our sapscript later on we wouldn't have any help from SAP.  Therefore our plan is still to migrate to the PDF forms, since those will have SAP support.  We're viewing the workaround as a sort of temporary last resort in case we need it, just to get the W-2s out for this year.
    - April

  • Java applet to printer

    Hello i was wondering is there a way to have a java applet print to a printer?

    Yes.Depending on what the applet is - a GUI or not?, the details are different. There are many, many existing threads about how to print from Java, try looking at some of them (that is, search for them.)

  • Basic Java Class with prints records out of the DEPT table

    Can some one show a basic java class which will query the DEPT table, and print them out?

    Nagarjuna,
    the Oracle DBMS JDBC Developer's Guide is full of code examples.
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/toc.htm
    --olaf                                                                                                                                                                                                                                                                                                                       

  • Java page footer printer

    I am trying to create a resident program, or a printer driver, or something like this, that will print a text (or graphic if possible) line at the end of everything (every print job) that is send to printer.
    Program has to work on Windows systems, with any printer that is installed. Laser, inkjet, matrix, POS printer - whatsoever. Note that some printers could have generic (text) drivers installed instead of original - manufacturers.
    Futhermore, note that paper size could be any - A4, A3, larger, smaller or even infinite paper (no cutter). In case of infinite paper, text (or graphic if possible) line should be printed after every printer job sent to the printer.
    I am trying to create a resident program, or a printer driver, or something like this, that will print a text (or graphic if possible) line at the end of everything (every print job) that is send to printer.
    Program has to work on Windows systems, with any printer that is installed. Laser, inkjet, matrix, POS printer - whatsoever. Note that some printers could have generic (text) drivers installed instead of original - manufacturers.
    Futhermore, note that paper size could be any - A4, A3, larger, smaller or even infinite paper (no cutter). In case of infinite paper, text (or graphic if possible) line should be printed after every printer job sent to the printer.
    Text (or graphic if possible) line that is send to the printer should be read out of a text (or binary) file.
    I have tried Java Printing but it prints the text when i execute the java program whereas the need is for a resident program that automatically prints the text when i print something from any program.
    Thanx n Regards.
    Salman.

    I really don't think Java is the way to go for something like this. You are talking about something that hooks right into the operating system. You may be able to do this with Windows shell-scripts but - more likely - it's going to requre C coding in a DLL with registry changes to invoke it.

  • Adding Print Button With Java Script to Print of Different Pages Differently

    Hi,
    I am in the process of making a form and most of it is done and now I want to be able to print off two of the pages but to different printers, I have one that needs to be printed off on a regular A4 printer and another that needs to go to a label printer. I have both of the names for the printers and I have tried something but it just doesnt do anything at all (this is suggested by adobe I think?)
    var pp = this.getPRintParam();
    var printamount = this.getValue("Quantity_Boxes");
    pp.printerName = "Zebra Technologies ZTC GK420t";
    pp.firstPage = 3;
    pp.lastPage = 3;
    pp.NumCopies = 2*printamount;
    this.print();
    I tried it without the first and last page and nothing happens, I am useing a shared printer which works when I do cmd + P which the full printer name is Zebra Technologies ZTC GK420t @ User's iMac. (I have also tried putting the full name in aswell)
    This is just to test one page so far but is there any way that one button will be able to print off 2 different pages to 2 different printers?
    If someone knows how this would be a great help!
    Thanks,
    Bruce

    Thanks for that, I have it working now but it shows the dialog box with no settings changed should i use:
    pp.interactive = pp.constants.interactionLevel.automatic ?
    Thanks,
    Bruce
    EDIT:
    It printed but only the first page but it printed on the right amount quantity was 2*3 wich was the result of the Quantity_Box value
    I want it to print page 3 through the Zebra Printer and have page 2 printed to a different printer, is this possible through one button?

  • I need to learn how to print in Java 1.4 (Printing  tutorial needed)

    Hi
    I need to find a really good Printing tutorial.
    Can anyone tell tell of a good tutorial.
    Please don't ask my to do a Google search as I have already :)
    Thanks
    Craig

    All you ever wanted to know about Oracle Reports:
    http://www.oracle.com/technetwork/middleware/reports/documentation/index.html

  • Java progarmming for printing graphics by Plotter

    Hi All Visitor,
    I want to write a program to take a print out of graphics by the plotter device. Any body who has experience to write a program for plotter are requested to share his experience.
    thanking You.

    Hi,
    Would you mind reposting your question over on the Flex forums?  You'll most likely have better luck over there.
    Thanks,
    Chris

Maybe you are looking for

  • Can't fix fglrx/Xorg black screen issue, no matter what I try!

    I've tried everything that I can think of or find online to fix this. Please help. I'm getting what seems to be an oft-recurring issue where Xorg simply won't start when using the fglrx driver. It boots fine with VESA or Xfree86-ati, but using fglrx

  • Regarding negative no s in committed quantity

    Dear all,                         While checking the stock status of a finished goods...............the value in the committed qty is coming as negative....and the value in the available qty is added up with the in stock value. Example:-             

  • How can I grab pics off of my broken Pre?

    I am a Volunteer here, not employed by HP. You too can become an HP Expert! Details HERE! If my post has helped you, click the Kudos Thumbs up! If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you

  • Should I uninstall Creative Cloud and CC apps before using migration assistant to my new imac?

    I have heard that Creative Cloud and CC apps dont transfer well with the Migration Assistant from Apple. I have a new iMac with Yosemite. Should I uninstall everything before using the Migration Assistant and then re-install Creative Cloud and apps a

  • JDeveloper 9i integration with PVCS

    I have read that JDeveloper 9i does not integrate with PVCS, is this true? If not, is support planned? Thanks