使用 C# 在 PDF 中添加页面印章

使用 C# 添加页面印章

当您需要应用包含图形、文本、表格的复合印章时,可以使用 PdfPageStamp。以下示例演示了如何使用印章创建类似于 Adobe InDesign、Illustrator、Microsoft Word 的文具。假设我们有一些输入文档,并希望应用两种蓝色和梅子色的边框。

以下代码片段也适用于 Aspose.PDF.Drawing 库。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddPageStamp()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "AddPageStampInput.pdf"))
    {
        //Create PdfPageStamps
        var bluePageStamp = new Aspose.Pdf.PdfPageStamp(dataDir + "AddPageStamp.pdf", 1)
        {
            Height = 800,
            Background = true
        };
        // Add stamps
        document.Pages[1].AddStamp(bluePageStamp);
        // Save PDF document
        document.Save(dataDir + "AddPageStamp_out.pdf");
    }
}