With PDF Extractor SDK, you can easily extract attachments from PDF files. Check the samples below to learn how to extract attachments from PDF files.
Also, check this article to learn how to extract pdf document info such as Author, Creator, Producer etc.
Select your programming language:
using System;
using System.IO;
using Bytescout.PDFExtractor;
namespace ExtractAttachments
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String inputFile = Server.MapPath(@"bin\attachments.pdf");
// Create Bytescout.PDFExtractor.AttachmentExtractor instance
AttachmentExtractor extractor = new AttachmentExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
// Load sample PDF document
extractor.LoadDocumentFromFile(inputFile);
Response.Clear();
Response.ContentType = "text/html";
for (int i = 0; i < extractor.Count; i++)
{
Response.Write("Saving attachment: " + extractor.GetFileName(i) + "<br>");
//extractor.Save(i, extractor.GetFileName(i)); // you can save into temp folder or save to Stream object to avoid temp files
Response.Write("File size: " + extractor.GetSize(i) + "<br>");
}
Response.End();
extractor.Dispose();
}
}
}
using System;
using Bytescout.PDFExtractor;
namespace ExtractAttachments
{
class Program
{
static void Main()
{
// Create Bytescout.PDFExtractor.AttachmentExtractor instance
AttachmentExtractor extractor = new AttachmentExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
// Load sample PDF document
extractor.LoadDocumentFromFile("attachments.pdf");
for (int i = 0; i < extractor.Count; i++)
{
Console.WriteLine("Saving attachment: " + extractor.GetFileName(i));
// Save attachment to file
extractor.Save(i, extractor.GetFileName(i));
Console.WriteLine("File size: " + extractor.GetSize(i));
}
extractor.Dispose();
}
}
}
Imports Bytescout.PDFExtractor
Module Module1
Sub Main()
' Create Bytescout.PDFExtractor.AttachmentExtractor instance
Dim extractor = New AttachmentExtractor()
extractor.RegistrationName = "demo"
extractor.RegistrationKey = "demo"
' Load sample PDF document
extractor.LoadDocumentFromFile("attachments.pdf")
For i As Integer = 0 To extractor.Count - 1
Console.WriteLine("Saving attachment: " + extractor.GetFileName(i))
' Save attachment to file
extractor.Save(i, extractor.GetFileName(i))
Console.WriteLine("File size: " + extractor.GetSize(i).ToString())
Next
extractor.Dispose()
End Sub
End Module
' Create Bytescout.PDFExtractor.extractor object
Set extractor = CreateObject("Bytescout.PDFExtractor.AttachmentExtractor")
extractor.RegistrationName = "demo"
extractor.RegistrationKey = "demo"
' Load sample PDF document with embedded attachments
extractor.LoadDocumentFromFile("..\..\attachments.pdf")
' Iterate through attachments and save them
For i = 0 To extractor.Count - 1
extractor.Save i, extractor.GetFileName(i) ' save in the current folder with original filename
Next
MsgBox "Done: " & CStr(extractor.Count) & " attachments extracted"
Set extractor = Nothing