Search code examples
javaswingprintingjeditorpane

Automatic Page Breaks using a JEditorPane


I'm using a JEditorPane to load some HTML content from a String so that I can print it. I load a HTML template and use String.format() to insert variables and other templates. I then call the print() function on a new JEditorPane.

That all works fine, but when it prints it does not properly paginate so that the elements are not trimmed off. I can get tables that are half on the bottom of one page, and half on the top of another page, with text split as well.

screenshot

I was wondering if anybody knew a solution to this, or if there is a better way to print HTML without using any not open-source libraries or default libraries.


Solution

  • I'd suggesting to read Printing tutorial, there is simple descriptions about Printing a Multiple Page Document, a few usefull examples here