通过 Java 处理 PDF 格式的邮票

使用 Java API 使用 Aspose.PDF 进行冲压。

如何使用 Java 库将图章添加到 PDF

为了在 PDF 中添加文本图章,我们将使用 Aspose.PDF for Java API,这是一款功能丰富、功能强大且易于使用的适用于 Java 平台的转换 API。你可以直接从 [Maven](https://repository.aspose.com/webapp/ #/artifacts/browse/Tree/General/repo/com/aspose/aspose-pdf)下载它的最新版本,然后通过在 pom.xml 中添加以下配置将其安装在基于 Maven 的项目中。

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

将图章添加到 PDF 文档 Java


你需要 Aspose.PDF for Java 才能在你的环境中试用这些代码。

1.使用 “文档” 实例加载 PDF。 1.使用 Document.Info 属性获取文档信息。 1.访问并显示不同的 Document.Info 属性。

将图章添加到 PDF-Java。


    // Open document
    Document pdfDocument = new Document(dataDir+ "AddTextStamp.pdf");

    // Create text stamp
    TextStamp textStamp = new TextStamp("Sample Stamp");
    // Set whether stamp is background
    textStamp.Background = true;
    // Set origin
    textStamp.XIndent = 100;
    textStamp.YIndent = 100;
    // Rotate stamp
    textStamp.Rotate = Rotation.on90;
    // Set text properties
    textStamp.TextState.Font = FontRepository.FindFont("Arial");
    textStamp.TextState.FontSize = 14.0F;
    textStamp.TextState.FontStyle = FontStyles.Bold;
    textStamp.TextState.FontStyle = FontStyles.Italic;
    textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
    // Add stamp to particular page
    pdfDocument.Pages[1].AddStamp(textStamp);

    dataDir = dataDir + "AddTextStamp_out.pdf";
    // Save output document
    pdfDocument.Save(dataDir);