执行自定义JavaScript
利用 IronPDF 的 ChromePdfRenderOptions.Javascript
属性,您可以指定在 PDF 页面加载为字符串后执行 JavaScript,从而实现动态内容渲染和交互性。
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
利用 IronPDF 的 ChromePdfRenderOptions.Javascript
属性,您可以指定在 PDF 页面加载为字符串后执行 JavaScript,从而实现动态内容渲染和交互性。