PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

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 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
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.