Extract embedded files from PDF
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