I am wondering if there is a way to use the html to pdf conversion and pass a 
page break.  I am passing a page break with css as <div 
style="page-break-before: always;">&nbsp;</div> but it does not recognize it.  
Is there another way to accomplish this?

This is how I am using iTextSharp 5.1.3.0 to convert the html to pdf:

 Function SaveHtmlToPDF(content As String, fname As String, title as String, 
author As String, pageType As String, pageOrient As String) As Integer
  '---20120326: Created.
  '---Uses iTextSharp API
  '--- Remove <hr> tags
  '--- add width attributes to TD
  '--- add align attributes to TD
  '--- add br at top of page to allow title to display properly
  '---Save content to fname (over-writes existing file)
  Dim currentContext As System.Web.HttpContext = System.Web.HttpContext.Current
  '---Save document to docs folder (pdf)
  Dim document As iTextSharp.text.Document
  if(lcase(pageType) = "legal") then
   if(pageOrient = "Landscape") then
    document = new 
iTextSharp.text.Document(iTextSharp.text.PageSize.Legal.Rotate, 25, 25, 25, 25)
   else
    document = new iTextSharp.text.Document(iTextSharp.text.PageSize.Legal, 25, 
25, 25, 25)
   end if
  else
   if(pageOrient = "Landscape") then
    document = new 
iTextSharp.text.Document(iTextSharp.text.PageSize.Letter.Rotate, 25, 25, 25, 25)
   else
    document = new iTextSharp.text.Document(iTextSharp.text.PageSize.Letter, 
25, 25, 25, 25)
   end if
  end if
  Dim filePath As String
  'filePath = Server.MapPath("~\"& systemDir &"\docs\"& strDetailId &"\"& 
strIncidentNo &"_Incident.pdf")
  filePath = currentContext.Server.MapPath(fname)
  PdfWriter.GetInstance(document, new FileStream(filePath, FileMode.Create))
  document.Open()
  'Dim pass_null As iTextSharp.text.html.simpleparser.StyleSheet
  Dim pass_null = new iTextSharp.text.html.simpleparser.StyleSheet()
  pass_null.LoadStyle("test", "color", "black") 
  'pass_null = Empty.Value
  'pass_null = Nothing
  'renderPage = "<html><body>hi</body></html>"
  Dim str_renderPage = new StringReader(content)
  Dim parsedHtmlElements As Object
  '---Note: Add tag attribute width and bgcolor for correct formating. HR tag 
is problematic.
  '---Replace <hr/> with <table border="& quote &"1"& quote &" width="& quote 
&"100%"& quote &"><tr><td>&nbsp;</td></tr></table>
  parsedHtmlElements = HTMLWorker.ParseToList(str_renderPage, pass_null)
  for each htmlElement As IElement in parsedHtmlElements
      'if( (InStr(htmlElement.ToString(),"<hr") > 0) or 
(InStr(htmlElement.ToString(),"<br") > 0) ) then
       '---skip
      'else
       document.Add(htmlElement)
      'end if
  next
  '---Add Document Title
  document.AddTitle(title)
  '---Add Document Author
  document.AddAuthor(author)
  document.Close
  return 1
 End Function

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to