Using the sample codes from here I come up with these codes -
var my_html = this.GetmyReportHtml();
var my_css = this.GetmyReportHtmlCss();
Byte[] bytes;
using (var ms = new MemoryStream())
{
using (var doc = new iTextSharp.text.Document(PageSize.LETTER))
{
using (var writer = PdfWriter.GetInstance(doc, ms))
{
doc.Open();
try
{
using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(my_css)))
{
using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(my_html)))
{
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss);
}
}
}
catch (Exception ex)
{
}
finally
{
doc.Close();
}
}
}
bytes = ms.ToArray();
}
System.IO.File.WriteAllBytes(@"c:\\temp\test.pdf", bytes);
PDF has been generated. However my_html has 6 pages in my case, only half of the content are converted to pdf.
Anyone knows what happened here? How to know if iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml works properly?
Thanks