简体   繁体   English

并非所有HTML页面都无法通过SelectPdf转换为PDF

[英]All HTML Pages are not converting to PDF with SelectPdf

I am using the following code to convert large HTML content to PDF using iTextSharp SelectPDF. 我正在使用以下代码使用iTextSharp SelectPDF将大型HTML内容转换为PDF。 None of the HTML pages are correctly converted. 没有正确转换HTML页面。 The data vanishes after 6 pages into the PDF. 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);
        }
    }

之所以发生这种情况,是因为您使用的是SelectPdf社区版本,该版本是免费的,其局限性是您最多只能转换为5-6页的pdf,如果您需要的更多,则需要使用非免费版本。从这里https://selectpdf.com/downloads/

The problem is that you are using SelectPdf community edition. 问题是您正在使用SelectPdf社区版。 According to SelectPdf ( http://selectpdf.com/community-edition/ ), the free version is limited to 5 pages. 根据SelectPdf( http://selectpdf.com/community-edition/ ),免费版本限于5页。

If you want to convert longer pages, you need to use the commercial edition, but that is not free. 如果要转换较长的页面,则需要使用商业版,但这不是免费的。

please use JsPdf this will become helpful for you.please see this link below to get source code and complete documentation. 请使用JsPdf,这将对您有所帮助。请查看下面的链接以获取源代码和完整的文档。

https://parall.ax/products/jspdf https://parall.ax/products/jspdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM