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 page runs in Chromium, the engine of the Chrome browser, with the JavaScript of a current browser.
ScriptsEnabled - JavaScript runs in the converted page (true by default).
WebGlEnabled - WebGL for pages drawn with it (3D charts, maps). Off by default, which makes conversions faster.
The conversion starts when the page has loaded. For content that appears later, use one of these:
Property | Use |
|---|---|
Wait a fixed number of seconds after the page loads. | |
Wait until the page sets window.status to the given text - the page says when it is ready. | |
StartupMode = Manual | Wait until the page calls ExpertPdfJSObj.startConversion(). See Start conversion from JavaScript. |
Give images that load when they scroll into view the time to load. | |
The maximum time to load the page (60 seconds by default). |
CustomCSS - CSS added to the page, for example to hide a cookie banner or a menu.
PostLoadingScript - JavaScript that runs after the page has loaded; PostLoadingScriptDelayAfter waits after it.
StartupScript - JavaScript injected into the page that runs before the scripts of the page.
ClickElementsSelectors - elements clicked before the conversion, for example the "close" button of a banner; ClickElementsDelayBefore and ClickElementsDelayAfter wait around the clicks.
PdfConverter converter = new PdfConverter(); 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");