\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/zh-hant/nodejs/examples/js-charts-to-pdf/#product"},"targetProduct":{"@id":"https://ironpdf.com/zh-hant/nodejs/examples/js-charts-to-pdf/#product"},"keywords":"在PDF中呈現圖表,Node.js中的JavaScript圖表和曲線圖,IronPDF waitFor屬性,如何使用Node.js將圖表新增到PDF中,執行JavaScript以進行PDF呈現,PDF建立中的JavaScript執行定時","datePublished":"2018-08-29","dateModified":"2026-06-29"}]}
IRONSOFTWAREHOME
在 PDF 中呈現圖表
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
在 PDF 中呈現圖表

在 PDF 中呈現圖表

使用JavaScript執行足夠的時間。 以下是如何配置此過程的範例:

在上面的程式碼中,我們已啟用了enableJavaScript屬性。 JavaScript執行。 這個特定配置,使用window.ironpdf.notifyRender函式或達到最大等待時間之前一直等待。

此外,HTML內容的視圖和佈局符合螢幕設定。

在GitHub上探索JS Charts到PDF的範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費線上演示
Booking Badge

獲得來自全球數百萬工程師的信賴

Iron Software的客戶徽標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的資料將始終保密。
獲得來自全球數百萬工程師的信賴
Iron Software的客戶徽標
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
Node.js模組下載PDF
使用npm安裝

版本: 2026.6

  1. 下載並安裝Node.js 12+。
  2. 在終端機中執行上述命令。

授權從$999起