高效新增 HTML 內容
from ironpdf import *

# Use HtmlStamper to stamp Html onto pdf
htmlStamper = HtmlStamper("<h1>Html stamp</h1>")
htmlStamper.VerticalOffset = Length(-200, MeasurementUnit.Pixel)
htmlStamper.HorizontalOffset = Length(-200, MeasurementUnit.Pixel)

# Use TextStamper to stamp text with custom font onto pdf
textStamper = TextStamper("Hello World! Stamp One Here!")
textStamper.FontFamily = "Bungee Spice"
textStamper.UseGoogleFont = True
textStamper.FontSize = 30

# Use ImageStamper to stamp images onto pdf
file_path = r'C:\Users\logo.png'
imageStamper = ImageStamper(file_path)
imageStamper.VerticalAlignment = VerticalAlignment.Top
imageStamper.MinWidth = Length(20)
imageStamper.MinHeight = Length(20)

# Use BarcodeStamper to stamp QR code/Barcode onto pdf
barcodeStamper = BarcodeStamper("IronPDF", BarcodeEncoding.Code39)
barcodeStamper.MaxHeight = Length(5)
barcodeStamper.VerticalAlignment = VerticalAlignment.Bottom
barcodeStamper.HorizontalAlignment = HorizontalAlignment.Left

stamps_list = List[Stamper]()
stamps_list.Add(htmlStamper)
stamps_list.Add(textStamper)
stamps_list.Add(imageStamper)
stamps_list.Add(barcodeStamper)

pdf = PdfDocument.FromFile("Unstamped.pdf")
pdf.ApplyMultipleStamps(stamps_list)
pdf.SaveAs("Stamped.pdf")
pip install ironpdf
高效新增 HTML 內容

高效新增 HTML 內容

IronPDF for Python 支援在一次操作中使用 ApplyMultipleStamps 將多個不同的印章——HTML、文字、圖像和條碼——應用於PDF文件。

入門指南

為每種型別的印章建立個別的印章物件,將它們新增到 List[Stamper] 集合中,然後在 PdfDocument 上調用 ApplyMultipleStamps 以一次性應用所有印章。

理解程式碼

  • HtmlStamper(html):將HTML片段印在PDF上。 支援 VerticalOffset 和 HorizontalOffset 來微調位置,使用基於像素的 Length 值。
  • TextStamper(text):用自定義字體設置印文字。 設置 UseGoogleFont = True 和 FontFamily 以使用任何名稱的Google字體。
  • ImageStamper(path):將圖像檔案印在PDF上。 使用 MinWidth 和 MinHeight 控制印章尺寸。
  • BarcodeStamper(value, encoding):生成並印製條碼或QR碼。 BarcodeEncoding.Code39 生成標準的Code 39條碼。
  • List[Stamper]():一個型別化的集合,持有混合型別的印章物件。
  • ApplyMultipleStamps(stamps_list):在一次高效的操作中將清單中的所有印章應用到文件的每一頁。

對齊和定位

每個印章支援 VerticalOffset 和 HorizontalOffset 以便在頁面上精確放置。

學習如何使用 IronPDF for Python 在PDF上印製印章!

準備開始了嗎?

版本:2026.11剛剛發布