>  기사  >  Java  >  Java 코드를 사용하여 PDF에 주석을 추가하는 방법

Java 코드를 사용하여 PDF에 주석을 추가하는 방법

王林
王林앞으로
2023-05-21 22:07:041758검색

Process

1. PDF 문서를 로드하려면 Document 클래스를 사용하세요.

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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제