←Select platform

EmbeddedFilesSchemas Property

Summary

Collection of the embedded file schemas found in this document.

Syntax
C#
Java
public IList<PDFSchema> EmbeddedFilesSchemas { get; } 

public java.util.List<PDFSchema> getEmbeddedFilesSchemas(); 

Property Value

Collection of the embedded file schemas 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 and EmbeddedFilesSchemas are empty collections when a new instance of PDFDocument is created. However, the IsPortfolio property will also be set to indicate whether this is a PDF portfolio document. Refer to IsPortfolio for more information.

Similarly, the HasEmbeddedFiles property will be set to true or false to indicate whether the document contains any embedded files using the schemas.

To find more information regarding the embedded files (such as the file name and its size), as well as schemas information such as schema type, 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.

Example

This example will generate an HTML file with a table containing links to the embedded files found in the document. If the document is a PDF portfolio, then table entries are created based on the schema and their values.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
 
public static void EmbeddedFilesSchemasExample(string inputFileName, string outputDir) 
{ 
   // Load the source document 
   PDFDocument pdfDocument = new PDFDocument(inputFileName); 
 
   // Parse the embedded files 
   pdfDocument.ParseDocumentStructure(PDFParseDocumentStructureOptions.EmbeddedFiles); 
 
   if (!Directory.Exists(outputDir)) 
      Directory.CreateDirectory(outputDir); 
 
   // Create the HTML file 
   string htmlFileName = Path.GetFileNameWithoutExtension(inputFileName); 
   htmlFileName = Path.ChangeExtension(htmlFileName, "html"); 
   htmlFileName = Path.Combine(outputDir, htmlFileName); 
   using (var writer = File.CreateText(htmlFileName)) 
   { 
      // add the HTML 
      writer.WriteLine("<html>"); 
      writer.WriteLine("  <head>"); 
      writer.WriteLine($"    <title>{Path.GetFileName(inputFileName)}</title>"); 
      writer.WriteLine("    <style>table, th, td {border: 1px solid black;}</style>"); 
      writer.WriteLine("  </head>"); 
      writer.WriteLine("  <body>"); 
 
      // Add the table 
      writer.WriteLine("    <table>"); 
 
      // Create HTML from the schema, only show the visible items 
 
      // Add the columns (the schema itself) 
      writer.WriteLine("      <tr>"); 
      // Add the file name and created, always exists 
      writer.WriteLine("        <th>FileName</th>"); 
      foreach (PDFSchema schema in pdfDocument.EmbeddedFilesSchemas) 
      { 
         if (schema.IsVisible) 
         { 
            // Add a column 
            writer.WriteLine($"        <th>{schema.Key}</th>"); 
         } 
      } 
      writer.WriteLine("      </tr>"); 
 
      // Add the rows (the embedded files) 
      foreach (PDFEmbeddedFile embeddedFile in pdfDocument.EmbeddedFiles) 
      { 
         // Extract this attachment to the output directory 
         // Note: FileName of an embedded file is not guaranteed to be unique, also, we will use it in 
         // an HTML file, so use a generic name based on the file number 
         string outputFileName = $"attachment-{embeddedFile.FileNumber}"; 
         PDFFile.ExtractEmbeddedFile(inputFileName, pdfDocument.Password, embeddedFile.FileNumber, Path.Combine(outputDir, outputFileName)); 
 
         writer.WriteLine("      <tr>"); 
         // Add the file name and make it a link to the file we extracted 
         string fileNameLink = $"<a href=\"./{outputFileName}\">{embeddedFile.FileName}</a>"; 
         writer.WriteLine($"        <td>{fileNameLink}</td>"); 
 
         // Add the schema value for this file 
         foreach (PDFSchema schema in pdfDocument.EmbeddedFilesSchemas) 
         { 
            string value = embeddedFile.SchemaValues[schema.Key]; 
            // Format if needed, the values are not used in this example 
            if (schema.SchemaType == PDFSchema.DateSchemaType) 
            { 
               DateTime date = schema.AsDate(value); 
               value = date.ToString("MM/dd/yyyy"); 
            } 
            else if (schema.SchemaType == PDFSchema.NumberSchemaType) 
            { 
               /*long number =*/ 
               schema.AsNumber(value); 
            } 
 
            // Add it to the table if visible 
            if (schema.IsVisible) 
            { 
               writer.WriteLine($"        <td>{value}</td>"); 
            } 
         } 
 
         writer.WriteLine("      </tr>"); 
      } 
 
      writer.WriteLine("    </table>"); 
      writer.WriteLine("  </body>"); 
      writer.WriteLine("</html>"); 
   } 
 
   pdfDocument.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Controls 
Imports Leadtools.Pdf 
Imports Leadtools.Svg 
Imports Leadtools.WinForms 
 
Public Shared Sub EmbeddedFilesSchemasExample(inputFileName As String, outputDir As String) 
   ' Load the source document 
   Dim pdfDocument As New PDFDocument(inputFileName) 
 
   ' Parse the embedded files 
   pdfDocument.ParseDocumentStructure(PDFParseDocumentStructureOptions.EmbeddedFiles) 
 
   If Not Directory.Exists(outputDir) Then 
      Directory.CreateDirectory(outputDir) 
   End If 
   ' Create the HTML file 
   Dim htmlFileName As String = Path.GetFileNameWithoutExtension(inputFileName) 
   htmlFileName = Path.ChangeExtension(htmlFileName, "html") 
   htmlFileName = Path.Combine(outputDir, htmlFileName) 
   Using writer As TextWriter = File.CreateText(htmlFileName) 
      ' add the HTML 
      writer.WriteLine("<html>") 
      writer.WriteLine("  <head>") 
      writer.WriteLine($"    <title>{Path.GetFileName(inputFileName)}</title>") 
      writer.WriteLine("    <style>table, th, td {border: 1px solid black;}</style>") 
      writer.WriteLine("  </head>") 
      writer.WriteLine("  <body>") 
 
      ' Add the table 
      writer.WriteLine("    <table>") 
 
      ' Create HTML from the schema, only show the visible items 
 
      ' Add the columns (the schema itself) 
      writer.WriteLine("      <tr>") 
      ' Add the file name and created, always exists 
      writer.WriteLine("        <th>FileName</th>") 
      For Each schema As PDFSchema In pdfDocument.EmbeddedFilesSchemas 
         If schema.IsVisible Then 
            ' Add a column 
            writer.WriteLine($"        <th>{schema.Key}</th>") 
         End If 
      Next 
      writer.WriteLine("      </tr>") 
 
      ' Add the rows (the embedded files) 
      For Each embeddedFile As PDFEmbeddedFile In pdfDocument.EmbeddedFiles 
         ' Extract this attachment to the output directory 
         ' Note: FileName of an embedded file is not guaranteed to be unique, also, we will use it in 
         ' an HTML file, so use a generic name based on the file number 
         Dim outputFileName As String = $"attachment-{embeddedFile.FileNumber}" 
         PDFFile.ExtractEmbeddedFile(inputFileName, pdfDocument.Password, embeddedFile.FileNumber, Path.Combine(outputDir, outputFileName)) 
 
         writer.WriteLine("      <tr>") 
         ' Add the file name and make it a link to the file we extracted 
         Dim fileNameLink As String = $"<a href=""./{outputFileName}"">{embeddedFile.FileName}</a>" 
         writer.WriteLine($"        <td>{fileNameLink}</td>") 
 
         ' Add the schema value for this file 
         For Each schema As PDFSchema In pdfDocument.EmbeddedFilesSchemas 
            Dim value As String = embeddedFile.SchemaValues(schema.Key) 
            ' Format if needed, the values are not used in this example 
            If schema.SchemaType = PDFSchema.DateSchemaType Then 
               Dim d As DateTime = schema.AsDate(value) 
               value = d.ToString("MM/dd/yyyy") 
            ElseIf schema.SchemaType = PDFSchema.NumberSchemaType Then 
               Dim number As Long = schema.AsNumber(value) 
            End If 
 
            ' Add it to the table if visible 
            If schema.IsVisible Then 
               writer.WriteLine($"        <td>{value}</td>") 
            End If 
         Next 
 
         writer.WriteLine("      </tr>") 
      Next 
 
      writer.WriteLine("    </table>") 
      writer.WriteLine("  </body>") 
      writer.WriteLine("</html>") 
   End Using 
 
   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