Extract embedded files from PDF

This code sample illustrates how to loop through embedded files in an existing PDF document and extract those attachments one by one and place them in a folder.

using (FileStream fileIn = new FileStream(
   "inputAttachments.pdf", FileMode.Open, FileAccess.Read))
{
    Document docIn = new Document(fileIn);

    foreach (EmbeddedFile embeddedFile in docIn.EmbeddedFiles)
    {
        using (FileStream fileOut =
            new FileStream(String.Format("Output\" + embeddedFile.FileName),
                FileMode.Create, FileAccess.Write))
        {
            embeddedFile.Write(fileOut);
        }
    }
}
Using fileIn As New FileStream("inputAttachments.pdf", FileMode.Open, FileAccess.Read)
    Dim docIn As New Document(fileIn)

    For Each embeddedFile As EmbeddedFile In docIn.EmbeddedFiles
        Using fileOut As New FileStream([String].Format("Output\" + embeddedFile.FileName),
                FileMode.Create, FileAccess.Write)
            embeddedFile.Write(fileOut)
        End Using
    Next
End Using
Download PDFKit.NET 4.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link. Alternatively, you may want to use the NuGet package manager to install our library.

Nuget ID

Use the NugetID and start right away, or download the package and install it handmatically