Heim  >  Artikel  >  Java  >  So fügen Sie mithilfe von Java-Code Anmerkungen zu PDF hinzu

So fügen Sie mithilfe von Java-Code Anmerkungen zu PDF hinzu

王林
王林nach vorne
2023-05-21 22:07:041757Durchsuche

Process

1. Verwenden Sie die Document-Klasse, um PDF-Dokumente zu laden.

2. Erstellen Sie ein TextAnnotation-Objekt und fügen Sie Textanmerkungen hinzu.

3. Legen Sie Kommentarattribute wie Titel und Thema fest.

4. Verwenden Sie die Border-Klasse, um den Anmerkungsrand festzulegen.

Verwenden Sie die Methode Document.getPages().get_Item(int).getAnnotations().add(Annotation), um dem Dokument Anmerkungen hinzuzufügen.

5. Verwenden Sie Document.save, um das aktualisierte PDF zu speichern.

Instanzen

// 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");

Das obige ist der detaillierte Inhalt vonSo fügen Sie mithilfe von Java-Code Anmerkungen zu PDF hinzu. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:yisu.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen