Hi,
Thank you for bringing to our attention the issue you encountered when trying to extract PDF attachments using our product. After investigating the matter, our development team has determined that this is not a bug, but rather an issue related to the structure of the PDF document.
Attachments in PDF documents can be in two places: under the Category node at the root of the document, or within an attachment annotation on a specific page. To extract attachments from both locations, please refer to the following code:
- Code: Select all
public void ExtractAttachments()
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file that contains attachments
doc.LoadFromFile("D:\\Trash\\PdfTest\\Report (26).pdf");
//Get the attachment collection of the PDF document
PdfAttachmentCollection attachments = doc.Attachments;
//Specific output folder path
string outputFolder = "d:\\Trash\\PdfTest\\";
//Loop through the collection
for (int i = 0; i < attachments.Count; i++)
{
//Write attachment to a file
File.WriteAllBytes(outputFolder + attachments[i].FileName, attachments[i].Data);
}
//Loop through each page
foreach(PdfPageBase page in pdf.Pages)
{
foreach(PdfAnnotation annotation in page.AnnotationsWidget)
{
if(annotation is PdfAttachmentAnnotationWidget)
{
PdfAttachmentAnnotationWidget attachmentAnnot = annotation as PdfAttachmentAnnotationWidget;
File.WriteAllBytes(outputFolder + attachmentAnnot.FileName, attachmentAnnot.Data);
}
}
}
}
Best regards,
Triste
E-iceblue support team