\\n\" +\n \" \\n\" +\n \" \\n\" +\n \" \\n\" +\n \" \\n\" +\n \" \\n\" +\n \" \\n\" +\n \" \\\"\";\n\nChromePdfRenderOptions renderingOptions = new ChromePdfRenderOptions();\nrenderingOptions.setEnableJavaScript(true);\nrenderingOptions.setWaitFor(new WaitFor(1000));\nrenderingOptions.setCssMediaType(CssMediaType.PRINT);\n\nPdfDocument pdf = PdfDocument.renderHtmlAsPdf(htmlWithJs, renderingOptions);\n\n// Save the PDF\ntry {\n pdf.saveAs(Paths.get(\"assets/js_chart.pdf\"));\n} catch(IOException exception) {\n exception.printStackTrace();\n}","about":{"@id":"https://ironpdf.com/java/examples/js-charts-to-pdf/#product"},"targetProduct":{"@id":"https://ironpdf.com/java/examples/js-charts-to-pdf/#product"},"keywords":"rendering charts and graphs in PDFs,Java PDF chart generation,IronPDF Java example,convert JavaScript charts to PDF in Java,Java HTML to PDF with charts,JavaScript chart libraries PDF conversion","datePublished":"2023-08-23","dateModified":"2026-08-02"}]}
IRONSOFTWAREHOME
Rendering Charts and Graphs in PDFs

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import com.ironsoftware.ironpdf.render.CssMediaType;
import java.io.IOException;
import java.nio.file.Paths;

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

ChromePdfRenderOptions renderingOptions = new ChromePdfRenderOptions();
renderingOptions.setEnableJavaScript(true);
renderingOptions.setWaitFor(new WaitFor(1000));
renderingOptions.setCssMediaType(CssMediaType.PRINT);

PdfDocument pdf = PdfDocument.renderHtmlAsPdf(htmlWithJs, renderingOptions);

// Save the PDF
try {
    pdf.saveAs(Paths.get("assets/js_chart.pdf"));
} catch(IOException exception) {
    exception.printStackTrace();
}
mvn install
Rendering Charts and Graphs in PDFs

Rendering Charts and Graphs in PDFs

IronPDF can render web pages containing charts, graphs, and other elements built with modern JavaScript technologies.

IronPDF supports WebGL, allowing it to process web canvas-built elements using the machine's hardware graphics capabilities.

IronPDF supports all third-party chart libraries, including:

  • C3.js
  • D3.js
  • Highcharts

The setEnableJavaScript method on the ChromePdfRenderOptions object enables the developer to enable the processing of JavaScript referenced internally or externally within a web page. This property must be set to true to allow IronPDF to process the JavaScript needed to render the charts and graphics on a webpage.

The setRenderDelay configures IronPDF to postpone its interpreting of a web page's JavaScript for a specified amount of time (in milliseconds) after it has loaded its DOM. This method is useful in ensuring that IronPDF's HTML-to-PDF converter captures content that appears on a web page seconds after a browser finishes loading it initially. This is particularly relevant for asynchronous JavaScript code that takes a long time to complete.

Refer to the JavaScript Charts to PDF Code Example for more details about additional methods available on the ChromePdfRenderOptions class.


Render JavaScript Charts into PDF

  1. Add IronPDF to your Maven project:
  2. Use ChromePdfRenderOptions to enable JavaScript and configure delay/media type.
  3. Render HTML (inline string, file, or URL) using PdfDocument.renderHtmlAsPdf(...).
  4. Save the output with saveAs(...).
Learn to Enable JavaScript for PDF Rendering
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.

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 IronPDF
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