Click or drag to resize

JavaScript and Page Loading

Pages built with JavaScript - charts, maps, single page applications, content loaded on demand - must finish running their scripts before the converter captures them. These properties of PdfConverter control JavaScript and decide when the page is ready. The Chromium and Blink engines run modern JavaScript; the WebKit engines run ES5 JavaScript.

Enabling JavaScript
  • ScriptsEnabled - JavaScript runs in the converted page (true by default).

  • ScriptsEnabledInImage - the same, when the PDF page is generated as an image (GenerateSelectablePdf = false).

  • WebGlEnabled - WebGL for pages drawn with it (3D charts, maps). Off by default, which makes conversions faster.

  • PluginsEnabled - browser plug-ins (WebKit engine).

Waiting for the page

The conversion starts when the page has loaded. For content that appears later, use one of these:

Property

Use

Engines

ConversionDelay

Wait a fixed number of seconds after the page loads.

all

WindowStatus

Wait until the page sets window.status to the given text - the page says when it is ready.

Chromium, Blink

StartupMode = Manual

Wait until the page calls ExpertPdfJSObj.startConversion(). See Start conversion from JavaScript.

see the property

LazyImagesLoadingEnabled, LazyImagesLoadingDelay

Give images that load when they scroll into view the time to load.

Chromium, Blink

NavigationTimeout

The maximum time to load the page (60 seconds by default).

all

PdfConverter converter = new PdfConverter();
converter.RenderingEngine = RenderingEngine.Chromium;

// the page runs: window.status = "ready"; when its charts are drawn
converter.WindowStatus = "ready";
converter.NavigationTimeout = 120;

converter.SavePdfFromUrlToFile("https://www.example.com/dashboard", "dashboard.pdf");
Changing the page before the conversion
  • CustomCSS - CSS added to the page, for example to hide a cookie banner or a menu (Chromium, Blink).

  • PostLoadingScript - JavaScript that runs after the page has loaded (Chromium, Blink).

  • StartupScript - JavaScript that runs before the scripts of the page (WebKit).

  • ClickElementsSelectors - elements clicked before the conversion, for example the "close" button of a banner (Chromium, Blink).

PdfConverter converter = new PdfConverter();
converter.RenderingEngine = RenderingEngine.Chromium;
converter.CustomCSS = "#cookie-banner, nav { display: none !important; }";
converter.PostLoadingScript = "document.querySelectorAll('details').forEach(function (d) { d.open = true; });";
converter.SavePdfFromUrlToFile("https://www.example.com/article", "article.pdf");
See Also