Java を使用した透かしアノテーション
Contents
[
Hide
]
透かしアノテーションの追加
- 入力 PDF を開き、透かし注釈を配置する矩形を定義してください。
- 作成する
WatermarkAnnotationをページに追加し、透かしテキストの状態と不透明度を設定してください。 - 透かしテキスト行を適用し、変更された PDF を保存してください。
public static void watermarkAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
WatermarkAnnotation watermarkAnnotation = new WatermarkAnnotation(
document.getPages().get_Item(1), new Rectangle(100, 0, 400, 100, true));
document.getPages().get_Item(1).getAnnotations().add(watermarkAnnotation);
TextState textState = new TextState();
textState.setForegroundColor(Color.getBlue());
textState.setFontSize(25);
textState.setFont(FontRepository.findFont("Arial"));
watermarkAnnotation.setOpacity(0.5);
watermarkAnnotation.setTextAndState(new String[]{"HELLO", "Line 1", "Line 2"}, textState);
document.save(outputFile.toString());
}
}