Java を使用したテキストベースの注釈
Contents
[
Hide
]
テキスト注釈の追加
- 入力 PDF を開き、テキスト注釈を配置する対象ページを選択してください。
TextAnnotationを作成し、その矩形を定義して、タイトル・サブジェクト・フラグ・カラーを設定してください。- 注釈をページに追加し、更新されたドキュメントを保存してください。
public static void textAnnotationAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
TextAnnotation textAnnotation = new TextAnnotation(
document.getPages().get_Item(1), new Rectangle(299.988, 613.664, 428.708, 680.769, true));
textAnnotation.setTitle("Aspose User");
textAnnotation.setSubject("Inserted text 1");
textAnnotation.setFlags(AnnotationFlags.Print);
textAnnotation.setColor(Color.getBlue());
document.getPages().get_Item(1).getAnnotations().add(textAnnotation, false);
document.save(outputFile.toString());
}
}
フリーテキスト注釈の追加
- ソース PDF を読み込み、対象ページとフリーテキスト注釈の矩形を選択してください。
FreeTextAnnotationを作成し、デフォルトの外観を初期化して、タイトルと色を設定してください。- ページに注釈を追加し、結果を保存してください。
public static void freeTextAnnotationAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(
document.getPages().get_Item(1),
new Rectangle(299, 713, 308, 720, true),
new DefaultAppearance());
freeTextAnnotation.setTitle("Aspose User");
freeTextAnnotation.setColor(Color.getLightGreen());
document.getPages().get_Item(1).getAnnotations().add(freeTextAnnotation);
document.save(outputFile.toString());
}
}