How to replace an existing attachment with a new one?

28 views
Skip to first unread message

Ryan

unread,
Jan 12, 2016, 4:56:08 PM1/12/16
to PDFTron PDFNet SDK
Q:

I have a file attachment annotation that points to word doc, and I want to replace it with a new one, how do I do that?

-----------------------------------------------------------------------
A:

The following code will replace attachment of the first annotation on page 1 (assuming that this is the FileAttachment annotation)

Annot annot = doc.GetPage(1).GetAnnot(0);
pdftron
.PDF.Annots.FileAttachment fileAttachment = new pdftron.PDF.Annots.FileAttachment(annot); // assumes annot is a FileAttachment type
FileSpec fileSpec = FileSpec.Create(doc, input_path + "new_attachment.docx");
fileAttachment.SetFileSpec(fileSpec);
doc
.Save(output_path + "out.pdf", SDFDoc.SaveOptions.e_remove_unused);

See the AnnotationTest sample, or search this forum post, for code on how to find annotations by other means, such as type.
Reply all
Reply to author
Forward
0 new messages