←Select platform

PDFEmbeddedFile Class

Summary

Properties of an embedded file (attachment) in this document.

Syntax
C#
C++/CLI
Java
Python
[SerializableAttribute()] 
public class PDFEmbeddedFile 
public class PDFEmbeddedFile 
public: 
   [SerializableAttribute] 
   ref class PDFEmbeddedFile 
class PDFEmbeddedFile: 
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 embedded files (attachments) of a PDF document can be read using the following:

The binary data of an embedded file can be extracted and saved to an output file or stream using PDFFile.ExtractEmbeddedFile.

PDFEmbeddedFile contains the following members:

Member Description
FileNumber 1-based file number of this embedded file. This is a unique value
FileName Embedded file name
ObjectNumber PDF object number of this embedded file. This is a unique value
Description Description of this embedded file. This is optional
FileSize Size of the file in bytes
Created Date this file was created
Modified Date this file was last modified
SchemaValues Values for the PDF schema if this PDF is a portfolio. This is optional

Note that the FileName may not be unique in the collection of embedded files found in a PDF document. Instead, use the FileNumber or ObjectNumber property to get a unique identifier for the embedded file.

FileNumber is used as the parameter to identify the embedded file to extract using PDFFile.ExtractEmbeddedFile.

Refer to PDFDocument.EmbeddedFiles for more information on using a PDFSchema with PDF portfolio and embedded files.

Example
C#
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(); 
} 
Requirements

Target Platforms

Help Version 22.0.2023.7.10
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.