高效新增 HTML 內容
import {PdfDocument, HorizontalAlignment, VerticalAlignment, MeasurementUnit, BarcodeType} from "@ironsoftware/ironpdf";

(async () => {
    // Import existing PDF
    const pdf = await PdfDocument.fromFile("unstamped.pdf");

    // Define HTML stamp options
    const htmlStampOptions = {
        verticalOffset: {
            unit: MeasurementUnit.pixel,
            value: -200,
        },
        horizontalOffset: {
            unit: MeasurementUnit.pixel,
            value: -200,
        },
    };

    await pdf.stampHtml("<h1>Html stamp</h1>", {htmlStampOptions: htmlStampOptions})

    // Define text stamp options
    const textStampOptions = {
        fontFamily: "Bungee Spice",
        useGoogleFont: true,
        fontSize: 30,
    };

    await pdf.stampText("Hello World! Stamp One Here!", {imageStampOptions: textStampOptions})

    // Define image stamp options
    const imageStampOptions = {
        minWidth: {
            unit: MeasurementUnit.Percentage,
            value: 250,
        },
        minHeight: {
            unit: MeasurementUnit.Percentage,
            value: 250,
        },
    };

    await pdf.stampImage("logo.png", {imageStampOptions: imageStampOptions})

    // Define barcode stamp options
    const barcodeStampOptions = {
        barcodeType: BarcodeType.code39,
        maxHeight: {
            unit: MeasurementUnit.Percentage,
            value: 5,
        },
        verticalAlignment: VerticalAlignment.Bottom,
        horizontalAlignment: HorizontalAlignment.Left,
    };

    await pdf.stampBarcode("IronPDF", {options: barcodeStampOptions})

    // Save the stamped PDF
    await pdf.saveAs("Stamped.pdf");
})();
npm i @ironsoftware/ironpdf
高效新增 HTML 內容

高效新增 HTML 內容

IronPDF提供多種蓋章選擇,包括HTML、文字、圖片和條碼蓋章。 您可以透過垂直和水平座標指定每個蓋章的位置。 然後可以使用垂直和水平偏移來微調位置達到像素級精準。

HTML蓋章是透過使用包含完整內嵌CSS設計能力的HTML片段來實現的。 若要了解如何有效利用HTML蓋章,請參訪IronPDF 蓋章指南。

如果您不需要需要線上載入的高級字體,文字蓋章可以是一個快速的HTML替代方案。 透過瀏覽IronPDF 文字蓋章文件來探索文字蓋章的效率。

圖片蓋章非常適合用來在PDF文件上快速新增標誌作為最後點綴。 每個蓋章還擁有opacity屬性,可調整其外觀。 圖片蓋章可以配置為浮水印蓋章。 通過檢閱IronPDF 浮水印教程了解更多關於圖片和浮水印蓋章的內容。

條碼蓋章在給定的PDF文件中生成並新增條碼,為文件提供完美的最後點綴。 欲了解條碼使用和自訂化的說明,請參閱IronPDF 條碼蓋章說明。

在GitHub上探索HTML蓋章範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.11剛剛發布