HTML Page breaks

This is a code example of iText PDF, discover more.

8th November 2015

Switch code for this example
 * Example written by Bruno Lowagie in answer to the following question:
package sandbox.xmlworker;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;

import sandbox.WrapToTest;

 * @author iText
public class HtmlPageBreaks {
    public static final String DEST = "results/xmlworker/page_breaks.pdf";
    public static final String HTML = "resources/xml/page_breaks.html";
    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        new HtmlPageBreaks().createPdf(DEST);
     * Creates a PDF with the words "Hello World"
     * @param file
     * @throws IOException
     * @throws DocumentException
    public void createPdf(String file) throws IOException, DocumentException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        // step 3;
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new FileInputStream(HTML));
        // step 5

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now