在 HTML 轉 PDF 中新增條碼
using IronPdf;
using IronPdf.Editing;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.WaitFor.RenderDelay(500);

// Load barcode via HTML
var barcodeHtml = @"<link href=""https://fonts.googleapis.com/css?family=Libre%20Barcode%20128""rel = ""stylesheet"" ><p style = ""font-family: 'Libre Barcode 128', serif; font-size:30px;""> Hello Google Fonts</p>";
var doc = renderer.RenderHtmlAsPdf(barcodeHtml);

// or use the BarcodeStamper
var barcodeStamp = new BarcodeStamper("Hello World", BarcodeEncoding.Code39);
doc.ApplyStamp(barcodeStamp);

// Export to a file or Stream
doc.SaveAs("bc-test.pdf");
NuGet Download
PM > Install-Package IronPdf
在 HTML 轉 PDF 中新增條碼

在 HTML 轉 PDF 中新增條碼

除了支援各種自訂字型如Google字型外,IronPDF也支援將條碼加蓋於您的PDF文件上。 這使得開發者能夠輕鬆地在呈現的PDF中包含條碼資訊。

使用IronPDF生成帶有條碼的PDF步驟

首先,確保IronPdf程式庫已安裝並已匯入您的專案中。 然後,初始化ChromePdfRenderer類別的實例,讓您能將HTML內容渲染成高品質的PDF文件。

接下來,您需要建立您的條碼內容。 以我們的案例如例,我們建立了一個HTML字串,其中包含了一個Google Fonts連結,使用"Libre Barcode 128"字型。 接著,使用RenderHtmlAsPdf方法將HTML內容轉換成新的PDF文件。

在HTML渲染後,建立一個包含"Hello World"文字的條碼印章,搭配Code39編碼格式。 此印章然後運用ApplyStamp方法塗抹到PDF文件上。

最後,生成的PDF使用SaveAs方法儲存為名為"bc-test.pdf"的檔案。 這個簡單的過程使您能有效地在您的C#應用程式中生產包含樣式文字和條碼內容的PDF。 須注意有些情況下,這項功能不支援某些條碼型別,例如QR碼。 在這些情況下,一個有效的解決方案是使用IronBarcode生成此條碼或QR碼,然後將其作為圖像新增到您的PDF中。

學習如何使用IronPDF在PDF中新增圖片
在GitHub上查看

準備開始了嗎?

Nuget Downloads 22,024,882版本:2026.11剛剛發布