我正在使用以下代码使用iTextSharp SelectPDF将大型HTML内容转换为PDF。没有一个HTML页面被正确转换。数据在6页之后消失到PDF中。所有的HTML页面都不会转换为PDF与SelectPdf
public static void CreatePDFFromHTMLFile(string HtmlStream, string FileName)
{
try
{
// read parameters from the webpage
string htmlString = HtmlStream;
string baseUrl = "";
string pdf_page_size = "A4";
PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize),
pdf_page_size, true);
string pdf_orientation = "Portrait";
PdfPageOrientation pdfOrientation =
(PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation),
pdf_orientation, true);
int webPageWidth = 1024;
int webPageHeight = 0;
HtmlToPdf converter = new HtmlToPdf();
// set converter options
converter.Options.PdfPageSize = pageSize;
converter.Options.PdfPageOrientation = pdfOrientation;
converter.Options.WebPageWidth = webPageWidth;
converter.Options.WebPageHeight = webPageHeight;
// create a new pdf document converting an url
PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);
doc.Save(FileName);
doc.Close();
}
catch (Exception ex)
{
Tracing.HandleException(ex);
}
}
有一个在iTextSharp的没有'HtmlToPdf'类,所以你的问题不应该被标记为iText的问题。我不知道'HtmlToPdf'是关于什么的(我是iText的原始开发者;如果iTextSharp中存在这样的类,我就知道了)。另外:如果你不共享HTML,不要期待答案。 –
看起来像SelectPDF给我:http://selectpdf.com/html-to-pdf/demo/convert-html-code-to-pdf.aspx我会更新标签,你可以批准我的编辑布鲁诺? –
也许OP是SelectPDF的当前用户,但不满意它?也许他们想切换到iText并且正在探索技术支持? –