HTML Page breaks

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

8th November 2015
admin-marketing

Switch code for this example

HtmlPageBreaks.java
  1. /**
  2.  * Example written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/27843338/converting-repeater-control-to-pdf-using-itextsharp-every-repeated-contents-shou
  4.  */
  5. package sandbox.xmlworker;
  6.  
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.pdf.PdfWriter;
  10. import com.itextpdf.tool.xml.XMLWorkerHelper;
  11.  
  12. import java.io.File;
  13. import java.io.FileInputStream;
  14. import java.io.FileOutputStream;
  15. import java.io.IOException;
  16. import sandbox.WrapToTest;
  17.  
  18. /**
  19.  *
  20.  * @author iText
  21.  */
  22. @WrapToTest
  23. public class HtmlPageBreaks {
  24.     public static final String DEST = "results/xmlworker/page_breaks.pdf";
  25.     public static final String HTML = "resources/xml/page_breaks.html";
  26.    
  27.     public static void main(String[] args) throws IOException, DocumentException {
  28.         File file = new File(DEST);
  29.         file.getParentFile().mkdirs();
  30.         new HtmlPageBreaks().createPdf(DEST);
  31.     }
  32.        
  33.     /**
  34.      * Creates a PDF with the words "Hello World"
  35.      * @param file
  36.      * @throws IOException
  37.      * @throws DocumentException
  38.      */
  39.     public void createPdf(String file) throws IOException, DocumentException {
  40.         // step 1
  41.         Document document = new Document();
  42.         // step 2
  43.         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
  44.         // step 3
  45.         document.open();
  46.         // step 4
  47.         XMLWorkerHelper.getInstance().parseXHtml(writer, document,
  48.                 new FileInputStream(HTML));
  49.         // step 5
  50.         document.close();
  51.     }
  52. }
Contact

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