ihorko ihorko - 1 month ago 22
ASP.NET (C#) Question

iTextPdf how to break page

I generate pdf file from html page using iTextPdf like:

iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
TextReader reader = new StringReader(HTML);
hw.Parse(reader);
document.Close();


but my html page is large and I need to add page brakes in specific palces.

How can I add these page breaks in pdf?

Thanks

Answer

There is a HTMLWorker.ParseToList. Can't you use that?

  1. Get n elements from ParseToList
  2. Add first x elements to PDF
  3. Call NewPage on PDF
  4. Add remaining elements to PDF
Comments