←Select platform

PDFDocument Class

Summary

Encapsulates a PDF document and allows PDF pages, objects and images to be read. * PDF Capability Required.

Syntax

C#
VB
Java
C++
public class PDFDocument : IDisposable 
Public Class PDFDocument  
public class PDFDocument 
public ref class PDFDocument  

Remarks

The PDFDocument class encapsulates a PDF document on disk and allows you to read the pages, objects and images from the document. The PDFDocument class contains the following functionality:

  • Create a PDFDocument from a PDF file on disk (with support for reading encrypted documents) using the PDFDocument(string fileName) and PDFDocument(string fileName, string password) constructors.

  • Load the PDF document at any resolution (dots per inch) using the Resolution property.

  • Get information about the PDF document. This encompasses properties or metadata such as author, subject and keywords through the DocumentProperties property, the security and encryption options to use with PDF document through the SecurityOptions property, whether it is encrypted and requires a password to read (using the IsEncrypted property) and the PDF file type (or version) (using the FileType property.

  • Use ParseDocumentStructure to parse the document structure (Table of Contents (TOC)) of the PDF document. The TOC is a list of PDF bookmark objects stored in the Bookmarks property, along with the internal links between pages (or jumps) found in the document stored in the InternalLinks property.

  • Automatically create a list of PDFDocumentPage objects and store them in the Pages property. This makes it possible to get information about any page in the PDF document (i.e. its size in PDF units, inches or pixels).

  • Use ParsePages to parse the objects of a range of pages (or all pages) in the document. This method can read the text items (characters), images, rectangles, hyperlinks, annotations, form fields, digital signatures, and fonts found in the pages of the documents.

  • Use GetPageImage to get a Leadtools.RasterImage render of a page or more from the PDF document at any resolution. Use GetThumbnail to get a thumbnail of any page in the document.

  • Use GetPageSvg(rastercodecs,int32,codecsloadsvgoptions) to get an Leadtools.ISvgDocument representation of one or more pages of the PDF document.

To create a PDFDocument from a PDF file on disk, use the PDFDocument(string fileName) constructor, passing the filename. If the document is encrypted with a password, then use the PDFDocument(string fileName, string password) constructor, which will automatically decrypt the document and read it. To find out whether a document is encrypted and requires a password, call the static PDFFile.IsEncrypted method.

Because the PDFDocument class implements the System.IDisposable interface, it is best that you follow the standard .NET dispose pattern when using the PDFDocument class. For more information, refer to the System.IDisposable interface documentation in MSDN.

NOTE:* This class is only included as part of the Advanced PDF Plugin. If you receive a "PDF Capability Required" error, please verify that your license supports this plugin before using these classes in an unlocked application.

Example

This example will create a PDFDocument object from a PDF file on disk and then display its properties.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
public void PDFDocumentExample() 
{ 
   string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
 
   // Create a PDF document for file 
   using (PDFDocument document = new PDFDocument(pdfFileName)) 
   { 
 
      // Show the file type and properties 
      Console.WriteLine("File type is : {0}", document.FileType); 
      Console.WriteLine("Contains : {0} pages", document.Pages.Count); 
      Console.WriteLine("----------:"); 
      foreach (PDFDocumentPage page in document.Pages) 
      { 
         Console.WriteLine("Page: {0}, size: {1} by {2} ({3} by {4} inches)", page.PageNumber, page.Width, page.Height, page.WidthInches, page.HeightInches); 
      } 
 
      PDFDocumentProperties props = document.DocumentProperties; 
      Console.WriteLine("Properties:"); 
      Console.WriteLine("----------:"); 
      Console.WriteLine("Title: {0}", props.Title); 
      Console.WriteLine("Author: {0}", props.Author); 
      Console.WriteLine("Subject: {0}", props.Subject); 
      Console.WriteLine("Keywords: {0}", props.Keywords); 
      Console.WriteLine("Creator: {0}", props.Creator); 
      Console.WriteLine("Producer: {0}", props.Producer); 
      Console.WriteLine("Created: {0}", props.Created); 
      Console.WriteLine("Modified: {0}", props.Modified); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Controls 
Imports Leadtools.Pdf 
Imports Leadtools.Svg 
Imports Leadtools.WinForms 
 
Public Sub PDFDocumentExample() 
   Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
 
   ' Create a PDF document for file 
   Using document As PDFDocument = New PDFDocument(pdfFileName) 
 
      ' Show the file type and properties 
      Console.WriteLine("File type is : {0}", document.FileType) 
      Console.WriteLine("Contains : {0} pages", document.Pages.Count) 
      Console.WriteLine("----------:") 
      For Each page As PDFDocumentPage In document.Pages 
         Console.WriteLine("Page: {0}, size: {1} by {2} ({3} by {4} inches)", page.PageNumber, page.Width, page.Height, page.WidthInches, page.HeightInches) 
      Next page 
 
      Dim props As PDFDocumentProperties = document.DocumentProperties 
      Console.WriteLine("Properties:") 
      Console.WriteLine("----------:") 
      Console.WriteLine("Title: {0}", props.Title) 
      Console.WriteLine("Author: {0}", props.Author) 
      Console.WriteLine("Subject: {0}", props.Subject) 
      Console.WriteLine("Keywords: {0}", props.Keywords) 
      Console.WriteLine("Creator: {0}", props.Creator) 
      Console.WriteLine("Producer: {0}", props.Producer) 
      Console.WriteLine("Created: {0}", props.Created) 
      Console.WriteLine("Modified: {0}", props.Modified) 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly