Copy Comments from one pdf to it’s replica

Dear Team,
I’m trying to copy comments from one pdf to it’s replica. Kindly let me know any possibilities to do? if yes could you please share code snippet for the same?BE.FC.01.WP.01.pdf (181.1 KB)

@ismailihn

Thanks for contacting support.

You may please use Aspose.Facades.AnnotationEditor.ExportAnnotationsXfdf() method to export annotations from your PDF file. Later you can import exported file for your replica using ImportAnnotationsFromXfdf() method. Please check following sample code snippet:

string[] gAnnoType =
            {
                AnnotationType.Caret.ToString(),
                AnnotationType.Circle.ToString(),
                AnnotationType.FileAttachment.ToString(),
                AnnotationType.FreeText.ToString(),
                AnnotationType.Highlight.ToString(),
                AnnotationType.Ink.ToString(),
                AnnotationType.Line.ToString(),
                AnnotationType.Link.ToString(),
                AnnotationType.Movie.ToString(),
                AnnotationType.Polygon.ToString(),
                AnnotationType.PolyLine.ToString(),
                AnnotationType.PrinterMark.ToString(),
                AnnotationType.Screen.ToString(),
                AnnotationType.Popup.ToString(),
                AnnotationType.Square.ToString(),
                AnnotationType.Squiggly.ToString(),
                AnnotationType.Stamp.ToString(),
                AnnotationType.StrikeOut.ToString(),
                AnnotationType.Text.ToString(),
                AnnotationType.TrapNet.ToString(),
                AnnotationType.Underline.ToString(),
                AnnotationType.Watermark.ToString(),
                AnnotationType.Widget.ToString()
            };
var pdfDocument = new Document(dataDir + "BE.FC.01.WP.01.pdf");
Facades.PdfAnnotationEditor editor = new Facades.PdfAnnotationEditor(pdfDocument);
MemoryStream vOutputStream = new MemoryStream();
editor.ExportAnnotationsXfdf(vOutputStream, 0, 1, gAnnoType);
var fs = new FileStream(dataDir + "annots.xfdf", FileMode.Create);
fs.Write(vOutputStream.ToArray(), 0, vOutputStream.ToArray().Length);
var doc = new Document(dataDir + "replica.pdf");
fs.Close();
vOutputStream.Close();
editor = new Facades.PdfAnnotationEditor(doc);
doc.ImportAnnotationsFromXfdf(dataDir + "annots.xfdf");
editor.Save(dataDir + "Imported.pdf");

In case you face any issue, please share your both PDF documents with us. We will test the scenario in our environment and address it accordingly.