iTextSharp的不能转换所有的HTML到PDF

问题描述:

使用示例codeS从here我拿出这些codeS -

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已经生成。然而my_html有6页,我的情况下,只有一半的内容转换为PDF格式。

PDF has been generated. However my_html has 6 pages in my case, only half of the content are converted to pdf.

任何人都知道这里发生了什么?如何知道是否iTextSharp.tool.xml.XMLWorkerHelper.GetInstance()。ParseXHtml正常工作?

Anyone knows what happened here? How to know if iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml works properly?

感谢

发现出了问题。在这条线的codeS -

Found out the problem. In this line of codes -

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

PageSize.LETTER不能来传递。

PageSize.LETTER can not be passed in.