ホームページ  >  記事  >  Java  >  Java コードを使用して PDF に注釈を追加する方法

Java コードを使用して PDF に注釈を追加する方法

王林
王林転載
2023-05-21 22:07:041758ブラウズ

プロセス

1. Document クラスを使用して PDF ドキュメントを読み込みます。

2. TextAnnotation オブジェクトを作成し、テキスト注釈を追加します。

3. タイトル、テーマ、その他のコメント属性を設定します。

4. Border クラスを使用して、注釈付きの Border を設定します。

Document.getPages().get_Item(int).getAnnotations().add(Annotation) メソッドを使用して、ドキュメントに注釈を追加します。

5. Document.save を使用して、更新された PDF を保存します。

// Open the source PDF document
Document pdfDocument = new Document("input.pdf");
 
// Create annotation
TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(200, 400, 400, 600));
 
// Set annotation title
textAnnotation.setTitle("Sample Annotation Title");
 
// Set annotation subject
textAnnotation.setSubject("Sample Subject");
textAnnotation.setState(AnnotationState.Accepted);
 
// Specify the annotation contents
textAnnotation.setContents("Sample contents for the annotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Border border = new Border(textAnnotation);
border.setWidth(5);
border.setDash(new Dash(1, 1));
textAnnotation.setBorder(border);
textAnnotation.setRect(new com.aspose.pdf.Rectangle(200, 400, 400, 600));
 
// Add annotation in the annotations collection of the page
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
 
// Save the output file
pdfDocument.save("output.pdf");

以上がJava コードを使用して PDF に注釈を追加する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。