Java によるウォーターマークの追加

Java を使用して PDF にウォーターマークを追加する方法

Java ライブラリにウォーターマークを追加

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>

Java を使用してウォーターマークを追加


ご使用の環境でコードを試すには、Aspose.PDF for Java ライブラリ が必要です。

1。Document のインスタンスを持つ PDF を読み込みます。 1。WatermarkArtifact のインスタンスを作成します。 1。WatermarkArtifact オブジェクトのプロパティを設定します。 1。Aspose.Pdf.Page.ArtifactsコレクションクラスのメソッドAddを使用してウォーターマークを追加します。 1。PDF ファイルを保存する

PDF にウォーターマークを追加-Java。

<% watermark.code-block.subtitle %>

Input file:

File not added

Output format:

Output file:

    // Open document
    Document doc = new Document(_dataDir + "text.pdf");
    FormattedText formattedText = new FormattedText("Watermark", java.awt.Color.BLUE,FontStyle.Courier, EncodingType.Identity_h, true, 72.0F);
    WatermarkArtifact artifact = new WatermarkArtifact();
    artifact.setText(formattedText);
    artifact.setArtifactHorizontalAlignment (HorizontalAlignment.Center);
    artifact.setArtifactVerticalAlignment (VerticalAlignment.Center);
    artifact.setRotation (45);
    artifact.setOpacity (0.5);
    artifact.setBackground (true);
    doc.getPages().get_Item(1).getArtifacts().add(artifact);
    doc.save(_dataDir + "watermark.pdf");