Execute Custom JavaScript

Effortlessly modify HTML content appearance with JavaScript code.

To achieve this, start by defining the JavaScript code. 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.

Finally, save the resulting PDF, which incorporates the effects of the executed JavaScript code (changing text color to red), as 'executed_js.pdf'.