Execute Custom JavaScript
With IronPDF's ChromePdfRenderOptions.Javascript
property, you can specify JavaScipt to be executed after the page has loaded as a string as shown in the example.
using IronPdf; var renderOptions = new ChromePdfRenderOptions(); // Example that change all to red style in JavaScript: renderOptions.Javascript = "document.querySelectorAll('h1').forEach(function(el){el.style.color='red';})"; // Make sure to use the render options object that you created: var renderer = new ChromePdfRenderer { RenderingOptions = renderOptions }; var pdf = renderer.RenderHtmlAsPdf("<h1>Happy New Year!</h1>"); pdf.SaveAs("executed_js.pdf");
Imports IronPdf Private renderOptions = New ChromePdfRenderOptions() ' Example that change all to red style in JavaScript: renderOptions.Javascript = "document.querySelectorAll('h1').forEach(function(el){el.style.color='red';})" ' Make sure to use the render options object that you created: Dim renderer = New ChromePdfRenderer With {.RenderingOptions = renderOptions} Dim pdf = renderer.RenderHtmlAsPdf("<h1>Happy New Year!</h1>") pdf.SaveAs("executed_js.pdf")
Install-Package IronPdf
With IronPDF's ChromePdfRenderOptions.Javascript
property, you can specify JavaScipt to be executed after the page has loaded as a string as shown in the example.
9 .NET API products for your office documents