我使用以下代码使用iTextSharp SelectPDF将大型HTML内容转换为PDF。没有正确转换任何HTML页面。数据在6页进入PDF后消失。
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);
}
}
答案 0 :(得分:1)
这种情况正在发生,因为您正在使用SelectPdf的社区版本,该版本是免费的,您只能转换为长度为5-6页的pdf,如果您需要更多,则需要使用非免费提供一个而不是https://selectpdf.com/downloads/
答案 1 :(得分:0)
问题是您使用的是SelectPdf社区版。根据SelectPdf(http://selectpdf.com/community-edition/),免费版本限制为5页。
如果您想要转换较长的页面,则需要使用商业版,但这不是免费的。
答案 2 :(得分:0)
请使用JsPdf这将对您有所帮助。请参阅下面的链接 获取源代码和完整的文档。