Search code examples
c#selectpdf

SelectPDF not Showing Grid Data


I'm using Select PDF - Community Edition to render the output of a web page (e.g. document). When I view the PDF...the data in the grids are empty.

  • And yes, the grid data does render when viewed normally
  • As a side-note...I am using Kendo Grids

As an experiment...I set the "MinPageLoadTime" property to 15 seconds...it does indeed take 15 seconds for the SAVE to execute...but oddly, still no records are displayed in the PDF's rendering of the grid.

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;
}

NO GRID DATA in the PDF:
enter image description here


Solution

  • Disclaimer: I work for SelectPdf.

    It could be a javascript error. Try to get the console log after conversion using converter.ConversionResult.ConsoleLog. See if there are any javascript errors.

    • The ConsoleLog object does not exist in older versions
    • Just upgrade to the latest version as listed here

    SelectPdf supports several rendering engines. The default WebKit rendering engine can render ES5 javascript. Newer ES6 javascript syntaxes might result in errors.

    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