IRONSOFTWAREHOME
HTML 轉 PDF 中的自訂字型
import {PdfDocument, WaitForType} from "@ironsoftware/ironpdf";

(async () => {
    // Define the HTML content with a custom font from Google Fonts
    const htmlWithFont = `
        <h1>Google Font</h1>
        <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
        <p style="font-family: 'Lobster', serif; font-size:30px;">Hello Google Fonts</p>
    `;

    // Configure render options
    const options = {
        // Delay render to finish font loading
        waitFor: {
            type: WaitForType.RenderDelay,
            maxWaitTime: 500,
        },
    };

    // Render HTML content with the custom font to a PDF
    const doc = await PdfDocument.fromHtml(htmlWithFont, { renderOptions: options });

    // Save the PDF
    await doc.saveAs("font.pdf");
})();
npm i @ironsoftware/ironpdf
HTML 轉 PDF 中的自訂字型

HTML 轉 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起