\n \n \n \n \n \n \n `;\n\n // Configure rendering options\n const options = {\n enableJavaScript: true,\n waitFor: {\n type: WaitForType.JavaScript,\n maxWaitTime: 1000, // 1000 milliseconds delay\n },\n cssMediaType: CssMediaType.Screen,\n };\n\n // Render HTML content to a PDF\n const pdf = await PdfDocument.fromHtml(htmlWithJs, { renderOptions: options })\n\n await pdf.saveAs(\"js-chart.pdf\");\n})();","about":{"@id":"https://ironpdf.com/nodejs/examples/js-charts-to-pdf/#product"},"targetProduct":{"@id":"https://ironpdf.com/nodejs/examples/js-charts-to-pdf/#product"},"keywords":"rendering charts in PDFs,JavaScript charts and graphs in Node.js,IronPDF waitFor property,how to add charts to PDF using Node.js,execute JavaScript for PDF rendering,JavaScript execution timing in PDF creation","datePublished":"2018-08-29","dateModified":"2026-05-09"}]}
IRONSOFTWAREHOME
Rendering Charts in PDFs
import {PdfDocument, WaitForType, CssMediaType} from "@ironsoftware/ironpdf";

(async () => {
    const htmlWithJs = `<!DOCTYPE html>
    <html>
        <head>
            <meta charset='utf-8' />
            <title>C3 Bar Chart</title>
        </head>
        <body>
            <div id='chart' style='width: 950px;'></div>
            <script src='https://d3js.org/d3.v4.js'></script>
            <!-- Load c3.css -->
            <link href='https://cdnjs.cloudflare.com/ajax/libs/c3/0.5.4/c3.css' rel='stylesheet'>
            <!-- Load d3.js and c3.js -->
            <script src='https://cdnjs.cloudflare.com/ajax/libs/c3/0.5.4/c3.js'></script>
            <script>
                Function.prototype.bind = Function.prototype.bind || function (thisp) {
                    var fn = this;
                    return function() {
                        return fn.apply(thisp, arguments);
                    };
                };
                var chart = c3.generate({
                    bindto: '#chart',
                    data: {
                        columns: [
                            ['data1', 30, 200, 100, 400, 150, 250],
                            ['data2', 50, 20, 10, 40, 15, 25]
                        ]
                    }
                });
                // Set delay
                setTimeout(function() {
                    window.ironpdf.notifyRender();
                }, 1000);
            </script>
        </body>
    </html>`;

    // Configure rendering options
    const options = {
        enableJavaScript: true,
        waitFor: {
            type: WaitForType.JavaScript,
            maxWaitTime: 1000, // 1000 milliseconds delay
        },
        cssMediaType: CssMediaType.Screen,
    };

    // Render HTML content to a PDF
    const pdf = await PdfDocument.fromHtml(htmlWithJs, { renderOptions: options })

    await pdf.saveAs("js-chart.pdf");
})();
npm i @ironsoftware/ironpdf
Rendering Charts in PDFs

Rendering Charts in PDFs

When loading charts using JavaScript, it's important to allow sufficient time for JavaScript execution. Below is an example demonstrating how to configure this process:

In the code above, we've enabled JavaScript execution using the enableJavaScript property. The waitFor property is used to delay the rendering process and wait for the JavaScript to execute. This specific configuration, using WaitForType.JavaScript, will wait until the window.ironpdf.notifyRender function is called in the script or until the maximum wait time is reached.

Additionally, the CSS media option will ensure that the view and layout of the HTML content adhere to the screen settings.

Explore JS Charts to PDF Example on GitHub
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Node.js Module Download for PDF
Install with npm

Version: 2026.8

  1. Download and install Node.js 12+.
  2. Execute the above command in the terminal.

Licenses from $999