IRONSOFTWAREHOME
Custom Fonts in HTML to PDF

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;

import java.io.IOException;
import java.nio.file.Paths;

String htmlWithFont = "<link href=\"https://fonts.googleapis.com/css?family=Lobster\"rel=\"stylesheet\"><p style=\"font-family: 'Lobster', serif; font-size:30px;\"> Hello Google Fonts</p>";
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setWaitFor(new WaitFor(500));

PdfDocument doc = PdfDocument.renderHtmlAsPdf(htmlWithFont, renderOptions);

// Save the PDF
try {
    doc.saveAs(Paths.get("assets/font.pdf"));
} catch (IOException exception) {
    String.format("Failed to save the PDF to the filesystem: %s", exception.getMessage());
    exception.printStackTrace();
}
mvn install
Custom Fonts in HTML to PDF

Custom Fonts in HTML to PDF

IronPDF從HTML文件完美呈現PDF文件,也包括自定義網頁字體的準確呈現,這些字體包含由Font Awesome和Bootstrap Components等程式庫提供的字型圖標。

IronPDF支援自定義SVG CSS字體包。 這包括由線上字體鑄造廠如Google Fonts提供的自定義網頁字體。

要正確地將包含一個或多個自定義字體的網頁轉換為PDF,開發者必須在renderDelay屬性設置為適當的值來實現,如下面的範例所示。 在大多數情況下,最小值500毫秒(或半秒)將足以確保所有自定義字體/圖標資產在IronPdf將所有網頁內容轉換為PDF之前完全載入。

請注意,由於安全原因,Azure託管的Windows應用程式不支援網頁字體。

學習使用IronPDF設置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天試用金鑰。
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中