←Select platform

EmbeddedFiles Property

Summary

Collection of the embedded files found in this document.

Syntax
C#
Java
public IList<PDFEmbeddedFile> EmbeddedFiles { get; } 

public java.util.List<PDFEmbeddedFile> getEmbeddedFiles(); 

Property Value

Collection of the embedded files found in this document. The default value is an empty collection.

Remarks

PDF documents support embedded files of any type. The file can be another PDF, a TIF file, a JPEG image, or any other binary or textual data.

The value of EmbeddedFiles is an empty collection when a new instance of PDFDocument is created. However, the HasEmbeddedFiles property will be set to true or false to indicate whether the document contains any embedded files.

Similarly, the IsPortfolio property will also be set to indicate whether this is a PDF portfolio document. Refer to IsPortfolio for more information.

To find more information regarding embedded files, such as the file name and size, the application must perform the following:

PDFFile.ExtractEmbeddedFile can then be used to extract the data of an embedded file into an output file or stream.

Refer to EmbeddedFilesSchemas for an example on how to read and process PDF portfolio schemas.

Example

This example will list and then extract all the embedded files from a PDF document into an output directory.

C#
VB
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(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Controls 
Imports Leadtools.Pdf 
Imports Leadtools.Svg 
Imports Leadtools.WinForms 
 
Public Shared Sub ExtractEmbeddedFiles(inputFileName As String, outputDir As String) 
   ' Load the source document 
   Dim pdfDocument As New PDFDocument(inputFileName) 
   If Not pdfDocument.HasEmbeddedFiles Then 
      Console.WriteLine("PDF does not have embedded files") 
      ' No embedded files 
      pdfDocument.Dispose() 
      Return 
   End If 
 
   ' Read the attachments 
   pdfDocument.ParseDocumentStructure(PDFParseDocumentStructureOptions.EmbeddedFiles) 
 
   If Not Directory.Exists(outputDir) Then 
      Directory.CreateDirectory(outputDir) 
   End If 
 
   For Each embeddedFile As PDFEmbeddedFile 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 
      Dim outputFileName As String = $"{embeddedFile.FileNumber}-{embeddedFile.FileName}" 
      Console.WriteLine($"  Extracting to {outputFileName}") 
      outputFileName = Path.Combine(outputDir, outputFileName) 
      PDFFile.ExtractEmbeddedFile(inputFileName, pdfDocument.Password, embeddedFile.FileNumber, outputFileName) 
   Next 
 
   pdfDocument.Dispose() 
End Sub 
Requirements
Target Platforms
Help Version 21.0.2021.3.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly