执行自定义 JavaScript

使用 IronPDF,通过 JavaScript 代码轻松修改 HTML 内容外观。 IronPDF 是 Iron Software 产品库的一部分,以其强大的 HTML 转 PDF 功能而闻名,同时还支持 JavaScript、CSS 等。

要实现这一点,首先要定义 JavaScript 代码。 In our example, we'll change the text color of all H1 tags to red.

Next, create a rendering options object and set the enableJavaScript property to true. Assign the previously defined JavaScript code to the javascript property within this object.

Utilize the PdfDocument.FromHtml method to render the HTML content into a PDF document. Pass the renderOptions object as the second parameter.

最后,将生成的 PDF 文件(其中包含了执行 JavaScript 代码的效果,即文本颜色变为红色)保存为"executed_js.pdf"。

要了解有关 IronPDF 或其他 Iron Software 库(如IronBarcodeIronOCR等)的功能的更多信息,请访问 Iron Software官方网站

立即探索执行自定义 JavaScript 代码示例!

准备开始了吗?
版本: 2025.12 刚刚发布