iTextSharp的不能转换所有的HTML到PDF [英] iTextSharp Can not Convert All HTML to PDF
问题描述
使用示例codeS从<一个href="http://stackoverflow.com/questions/25164257/how-to-convert-html-to-pdf-using-itextsharp">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.
这篇关于iTextSharp的不能转换所有的HTML到PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!