How to get PDF attachment information in C#

Attachment is frequently used in PDF for it enables to add different file formats to the PDF files, such as image, PDF, word documents and excel documents. Using Spire.PDF for .NET, developers can add attachment and remove attachment in the PDF. This article will show you how to get the PDF attachment information in a PDF document.

Firstly, check the PDF file with the attachment that we need to get its attachment information.

How to get PDF attachment information in C#

Secondly, please check the steps as below of how to get the attachment information.

Step 1: Create a new PDF document and load from the file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("sample.pdf");

Step 2: Get a collection of attachments on the PDF document.

PdfAttachmentCollection collection = pdf.Attachments;

How to get PDF attachment information in C#

Step 3: Get the first attachment.

PdfAttachment attachment = collection[0];

Step 4: Get the attachment information for the first attachment.

Console.WriteLine("Name: {0}", attachment.FileName);
Console.WriteLine("Description: {0}", attachment.Description);
Console.WriteLine("Creation Date: {0}", attachment.CreationDate);
Console.WriteLine("Modification Date: {0}", attachment.ModificationDate);

How to get PDF attachment information in C#

Step5: Save the first attachment to the file.

File.WriteAllBytes(attachment.FileName, attachment.Data);

Effective screenshot of the attachment getting by Spire.PDF:

How to get PDF attachment information in C#