com.aspose.pdf.PageCollection pageCollection = document.getPages();
int index;
PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();
annotationEditor.bindPdf(document);
for (Page page : pageCollection) {
for (index = 1; index <= page.getAnnotations().size(); index++) {
String x = page.getAnnotations().get_Item(index).toString();
if(!x.contains("pdf.WidgetAnnotation")) {
annotationEditor.deleteAnnotation(page.getAnnotations().get_Item(index).getName());
}
}
}
By removing the comments/ annotations also the reference links (links within the document) are removed from my document. This is an unwanted behavior.
Is there a way to differentiate between comments (- witch I want to remove) to reference links (- that should remain)?
@LeahGreen I am afraid your question is no clear enough. Could you please attach your input, output and expected documents here for our reference? We will check the issue and provide you more information.
Thanks @alexey.noskov ,
I am attaching here an example document.
in the title: " Hello this is an example document" you can see I added a comment on the word “Is”.
this kind of comments I would like to remove from my documents when I generate them to PDF.
in the text: “Please refer to the Conclusion for more details.” if you click ctrl + mouse click on the word “conclusion” you will be referenced by a cross link to the conclusion at the bottom of the page. these kind of cross links I do not want to remove from my documents when generating to PDF.
In the previous message I shared the code that removes the comments from my documents.
Currently both, comments + cross links are being removed.
Is there a way to remove only comments and not cross links?
In order to filter only text annotations and leave the link annotations intact, you can do something like below:
try (com.aspose.pdf.Document doc = new com.aspose.pdf.Document(dataDir + "test_document_hyperlinks_bookmarks.pdf")) {
// Iterate through pages in the document
for (Page page : doc.getPages()) {
// Iterate through annotations on the page
for (com.aspose.pdf.Annotation annot : page.getAnnotations()) {
// Skip LinkAnnotations
if (annot instanceof LinkAnnotation) {
continue;
}
// else delete the annotation
}
}
// Save the flattened document
doc.save(dataDir + "flattened.pdf");
}
In case you still face any issues, please share the PDF file as sample source file so that we can further proceed accordingly.
Hi @asad.ali
Thank you so much for your response.
I tried the code you suggested, it works great for the cross references, and they are not being deleted by generation.
At the same time, the comments are also remaining, while I want them to be removed.
I am attaching here a pdf document with one comment and one reference link. please guide me how to remove the comment and leave the cross reference link.
Thanks again. Example doc.pdf (40.9 KB)
We checked your document and it seemed to have two annotations and both are LinkAnnotation. Therefore, the API is not able to detect any comment/TextAnnotation and delete it. We believe that the engine that you are using to convert source Word file into PDF documents, is not processing the comments as Text Annotations in converted PDF documents.
Do you happen to have such documents a lot or this is the only instance? We can log an investigation ticket in our issue management system to analyze the feasibility to differentiate for such files. Please provide your feedback so that we can further proceed accordingly.
Hi @asad.ali ,
I used Word to create the document. Added a comment + Cross reference and finally did Export to PDF.
This is a scenario that our customers use very frequently and we had the issue raising over and over.
I will truly appreciate your investigation and adding the ability to define comments separately than links.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-44623
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.