IRONSOFTWAREHOME
將 HTML 中的 BarCode 加入 PDF
from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()
renderer.RenderingOptions.WaitFor.RenderDelay(500)

# Load barcode via HTML
barcode_html = '''<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>'''
doc = renderer.RenderHtmlAsPdf(barcode_html)

# or use the BarcodeStamper
barcode_stamp = BarcodeStamper("Hello World", BarcodeEncoding.Code39)
doc.ApplyStamp(barcode_stamp)

# Export to a file or Stream
doc.SaveAs("bc-test.pdf")
pip install ironpdf
將 HTML 中的 BarCode 加入 PDF

將 HTML 中的 BarCode 加入 PDF

Python 開發者可以使用 IronPDF for Python 以兩種方式將條碼新增到他們的 PDF 文件中,如上所示:

方法 1:使用 ChromePdfRenderer 新增條碼

使用此方法來建立包含文字資訊的條碼:

  1. 建立一個字串變數,保存下列 HTML 元素:
    • 一個 link 元素,引用像 此條碼網頁字體。
    • 一個包含您要編碼於條碼中的文字的元素。
  2. 建立一個新的 ChromePdfRenderer 物件。
  3. 在新物件上使用字串變數作為參數調用 RenderHtmlAsPdf 方法。
  4. 把得到的 PdfDocument 物件保存到文件中。

方法 2:使用 BarcodeStamper 新增條碼

當您希望對條碼的外觀進行更多控制時(例如,寬度、高度、頁面位置等),使用此方法:

  1. 建立一個 PdfDocument 物件,如下所示。

  2. 建立一個 BarcodeStamper 物件,並在參數列表中指定要編碼的文字和目標 Barcode 格式(寬度和高度是可選的)。

  3. 在 PdfDocument 物件上調用 apply_stamp 方法。

  4. 保存更改。

using IronBarcode C# 程式庫 來獲得對條碼建立的更多控制。 (然後使用 IronPDF for Python 的 HtmlStamper 將它們蓋上到您的 PDFs 上!)

  • 注意:對於上面的 Python 範例,將 ChromePdfRenderer() 和方法名稱替換為正確的 Python 程式庫方法,並根據程式碼塊頂部的匯入適當地初始化。
學習使用 IronPDF for Python 建立 PDF
在GitHub上查看

準備開始了嗎?

版本:2026.9剛剛發布

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的Python模塊下載
使用pip安裝

版本: 2026.9

  1. 下載並安裝Python 3.7+。
  2. 如果尚未安裝,請從 pypi.org 安裝 pip。
  3. 在終端執行上述命令。
Python PDF模塊
下載模塊

版本: 2026.9

手動安裝到您的專案中

  1. 下載套件
  2. 從終端運行此命令
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

從$999起的授權