Indicates whether this PDF document has any embedded files (attachments).
public bool HasEmbeddedFiles {get;}
public boolean hasEmbeddedFiles();
public:
property bool HasEmbeddedFiles
{
bool get()
}
HasEmbeddedFiles # get (PDFDocument)
true if the PDF document has embedded files; otherwise, false.
IsPortfolio and HasEmbeddedFiles are automatically populated by the PDFDocument constructor.
If the value of HasEmbeddedFiles is true, then this PDF file has one or more embedded files (attachments). The properties of these files can be obtained using ParseDocumentStructure with PDFParseDocumentStructureOptions.EmbeddedFiles. When this method returns the values of EmbeddedFiles and EmbeddedFilesSchemas will be populated.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Pdf;
using Leadtools.Svg;
using Leadtools.WinForms;
public static void ExtractEmbeddedFiles(string inputFileName, string outputDir)
{
// Load the source document
PDFDocument pdfDocument = new PDFDocument(inputFileName);
if (!pdfDocument.HasEmbeddedFiles)
{
Console.WriteLine("PDF does not have embedded files");
// No embedded files
pdfDocument.Dispose();
return;
}
// Read the attachments
pdfDocument.ParseDocumentStructure(PDFParseDocumentStructureOptions.EmbeddedFiles);
if (!Directory.Exists(outputDir))
Directory.CreateDirectory(outputDir);
foreach (PDFEmbeddedFile embeddedFile in pdfDocument.EmbeddedFiles)
{
// Show this file information
Console.WriteLine($"Number:{embeddedFile.FileNumber}");
Console.WriteLine($" FileName:{embeddedFile.FileName}");
Console.WriteLine($" FileSize:{embeddedFile.FileSize}");
Console.WriteLine($" Description:{embeddedFile.Description}");
Console.WriteLine($" Created:{embeddedFile.Created}");
Console.WriteLine($" Modified:{embeddedFile.Modified}");
// Extract this attachment to the output directory
// Note: FileName of an embedded file is not guaranteed to be unique, therefore, we will append
// the file number which is unique to the output name
string outputFileName = $"{embeddedFile.FileNumber}-{embeddedFile.FileName}";
Console.WriteLine($" Extracting to {outputFileName}");
outputFileName = Path.Combine(outputDir, outputFileName);
PDFFile.ExtractEmbeddedFile(inputFileName, pdfDocument.Password, embeddedFile.FileNumber, outputFileName);
}
pdfDocument.Dispose();
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document