0

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

Community
  • 1
  • 1
Don
  • 1,532
  • 4
  • 24
  • 47

1 Answers1

0

Found out the problem. In this line of codes -

using (var doc = new iTextSharp.text.Document(PageSize.LETTER))

PageSize.LETTER can not be passed in.

Don
  • 1,532
  • 4
  • 24
  • 47
  • Hi Guys, After I removed the PageSize.LETTER, it generated all pages of PDF for me. But today when I test it again, the problem appears again. my_html has all the pages available. But only half of PDF pages are generated. Anyone knows what is the problem? – Don Mar 11 '15 at 17:03