首页 > 解决方案 > SelectPDF 不显示网格数据

问题描述

我正在使用Select PDF - Community Edition来呈现网页的输出(例如文档)。当我查看 PDF 时……网格中的数据是空的。

作为一个实验......我将“MinPageLoadTime”属性设置为 15 秒......执行 SAVE 确实需要 15 秒......但奇怪的是,在 PDF 的网格渲染中仍然没有显示任何记录。

public byte[] ToPDF(IPdfConverterArgs args)
{
    if (args == null)
        throw new ArgumentNullException();

    if (!(args is SelectPdfUrlConverterArgs))
        throw new ArgumentException(string.Format("Args.Type '{0}' is not a valid type.", typeof(SelectPdfUrlConverterArgs).Name));

    var arguments = args as SelectPdfUrlConverterArgs;

    if (string.IsNullOrWhiteSpace(arguments.Url))
        throw new ArgumentNullException();

    var pdfPageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), arguments.PdfPageSize, true);
    var pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), arguments.PdfOrientation, true);

    HtmlToPdf converter = new HtmlToPdf();

    converter.Options.PdfPageSize = pdfPageSize;
    converter.Options.PdfPageOrientation = pdfOrientation;
    converter.Options.WebPageWidth = arguments.WebPageWidth;
    converter.Options.WebPageHeight = arguments.WebPageHeight;
    converter.Options.MinPageLoadTime = arguments.MinPageLoadTime; //<<< In my testing...I temporarily set this to 15 (for seconds)

    PdfDocument doc = converter.ConvertUrl(arguments.Url);
    var bytes = doc.Save();

    return bytes;
}

PDF 中没有网格数据:
在此处输入图像描述

标签: c#selectpdf

解决方案


免责声明:我为 SelectPdf 工作。

这可能是一个 javascript 错误。尝试使用converter.ConversionResult.ConsoleLog获取转换后的控制台日志。查看是否有任何 javascript 错误。

SelectPdf 支持多种渲染引擎。默认的 WebKit 渲染引擎可以渲染 ES5 javascript。较新的 ES6 javascript 语法可能会导致错误。

HtmlToPdf converter = new HtmlToPdf();

converter.Options.PdfPageSize = pdfPageSize;
converter.Options.PdfPageOrientation = pdfOrientation;
converter.Options.WebPageWidth = arguments.WebPageWidth;
converter.Options.WebPageHeight = arguments.WebPageHeight;
converter.Options.MinPageLoadTime = arguments.MinPageLoadTime;

PdfDocument doc = converter.ConvertUrl(arguments.Url);
// At this point...you can look at the ConsoleLog object off of the ConversionResult to find any JavaScript Errors

推荐阅读