PDF Annotation

Please let me know if the below functionality can be done using “aspose.pdf-21.1-java.jar" related to PDF Annotation.

• Put comments in PDF document
• Save all comments
• Retrieve all comments when open the PDF document in Annotation mode
• Export all comments
• Import comments from the external document
• Highlight/Strike through/insert/replace text
• Reply to own comments
• Reply to other comments
• Comments save with date time

@swarupdey

You can surely achieve these functionalities using Aspose.PDF for Java. Please check the below useful links in the API documentation:

You can further use Annotation.setInReplyTo() method in order to reply to an annotation. The method takes Annotation as an argument to which you want to add reply.

Please feel free to let us know in case you need further information.

Thanks Team. Just checking Export-Import annotation functionality. Export to XFDF is working but while importing that to a file the file is getting generated but no annotation is observed. Seems “form.importXfdf(xfdfInputStream)” is not working properly. Please confirm is this because the evaluation copy of jar or something else.

code snippet below using same as example provide in “Import Data into a PDF File - facades|Aspose.PDF for Java

// For complete examples and data files, please go to GitHub - aspose-pdf/Aspose.PDF-for-Java: Aspose.PDF for Java examples, plugins and showcases
//Open document
com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form();
form.bindPdf(MyDir + “test_out_anno.pdf”);
//Open XFDF file.
java.io.FileInputStream xfdfInputStream = null;
try {
xfdfInputStream = new FileInputStream(MyDir+“EXannotations.xfdf”);
//Import XFDF data
form.importXfdf(xfdfInputStream);
//close file stream
xfdfInputStream.close();
//Save updated PDF
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

	form.save(MyDir + "test_out_note11.pdf");
	//dispose the form object
	form.dispose();

@swarupdey

Could you please share your sample source PDF document and XFDF file for our reference. Also, please try to share an expected output PDF as well. We will test the scenario in our environment and address it accordingly.

PS: With evaluation version, API can only process 4 elements of any collection e.g. Annotations, Pages, Paragraphs, etc.

while checking, I just want to extract the annotation from one document(example doc1.pdf) and then apply the same over another document (example doc2.pdf) . Extraction can be done but while apply the annotation to another document we did not find any annotation while opening the output document,

doc1.pdf = test_anno - Copy.pdf (99.3 KB)
doc2.pdf= test_out_anno.pdf (61.5 KB)

@swarupdey

We tested the scenario using the below code snippet and Aspose.PDF for Java 21.2. The output PDF file generated fine and all annotations were imported successfully.

String[] gAnnoType =
{
 "Caret",
 "Circle",
 "FileAttachment",
 "FreeText",
 "Highlight",
 "Ink",
 "Line",
 "Link",
 "Movie",
 "Polygon",
 "PolyLine",
 "PrinterMark",
 "Screen",
 "Popup",
 "Square",
 "Squiggly",
 "Stamp",
 "StrikeOut",
 "Text",
 "TrapNet",
 "Underline",
 "Watermark",
 "Widget"
};
Document pdfDocument = new Document(dataDir + "test_anno - Copy.pdf");
com.aspose.pdf.facades.PdfAnnotationEditor editor = new com.aspose.pdf.facades.PdfAnnotationEditor(pdfDocument);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
editor.exportAnnotationsXfdf(bos, 0, 1, gAnnoType);
OutputStream outputStream  = new FileOutputStream(dataDir + "annots.xfdf");
bos.writeTo(outputStream);
Document doc = new Document(dataDir + "test_out_anno.pdf");
outputStream.close();
editor = new com.aspose.pdf.facades.PdfAnnotationEditor(doc);
doc.importAnnotationsFromXfdf(dataDir + "annots.xfdf");
editor.save(dataDir + "Merged.pdf");

Merged.pdf (63.6 KB)

Also, we tested the scenario using a valid license file. Could you please try to use a valid or free 30-days temporary license at your end and let us know if the issue still persists?