Leadtools.Pdf Namespace : PDFFile Class |
[SerializableAttribute()] public class PDFFile
'Declaration <SerializableAttribute()> Public Class PDFFile
'Usage Dim instance As PDFFile
public sealed class PDFFile
function Leadtools.Pdf.PDFFile()
[SerializableAttribute()] public ref class PDFFile
The PDFFile class allows you to perform the following actions on Adobe Document Format (PDF) and Postscript (PS) files:
Get the PDF or PS version of a file with the GetPDFFileType method
Determine if a PDF file is encrypted with the IsEncrypted method
Get the PDF file properties or metadata (such as title, author, keywords, etc.) with the Load method
Update the properties of any PDF file with the SetDocumentProperties method
Get the number and size of pages in a PDF file with the GetPageCount method and Pages property
Quickly convert any PDF file to PDF/A while optionally updating its properties with the ConvertToPDFA method
Linearize (optimize for Web viewing) any PDF file while optionally updating its properties with the Linearize method
Convert or encrypt any PDF file from any version to another using the Convert method.
Convert any Postscript file to PDF with the Distill method
Merge a range or all pages from multiple existing PDF files into a single PDF file with the MergeWith method
Extract all or range of pages from an existing PDF file with the ExtractPages method
Delete range of pages from an existing PDF file with the DeletePages method
Insert all or range of pages from an existing PDF file into another using the InsertPagesFrom method
Replace all or range of pages from an existing PDF file into another using the ReplacePagesFrom method
Write bookmarks to an existing PDF files to update its Table of Contents (TOC) with the WriteBookmarks method
All the methods described above can set the compatibility level (version) of the created or updated PDF using the CompatibilityLevel property, update its properties using the the DocumentProperties property or set the security and encryption mode using the SecurityOptions property.
To use most of these properties methods, you must construct a PDFFile object with the PDF file and optional password before performing the action.
The C# and VB PDF File Demo shipped with LEADTOOLS contains a wizard style user interface to perform all the action above on existing PDF and PS files.
You can also use the PDFDocument class to parse a PDF file and extract its objects such as text (without invoking OCR), images, hyperlinks, internal links and bookmarks.
* NOTE: This class is only included as part of our Advanced PDF Plugin. If you receive a PDF Capability Required error, please check that your license supports this plugin before using these classes in an unlocked application.
Public Sub PDFFileExample() Dim sourceFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD.pdf") Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD_14.pdf") ' Load the properties of the file ShowProperties("Source file", sourceFileName) ' Update the properties of the file Dim pdfFileObj As New PDFFile(sourceFileName) pdfFileObj.DocumentProperties = New PDFDocumentProperties() pdfFileObj.DocumentProperties.Author = "Me" pdfFileObj.DocumentProperties.Title = "My title" pdfFileObj.DocumentProperties.Subject = "My subject" pdfFileObj.DocumentProperties.Creator = "My application" pdfFileObj.DocumentProperties.Modified = DateTime.Now pdfFileObj.SetDocumentProperties(destFileName) ' Show the properties of the new file ShowProperties("Destination file", destFileName) End Sub Private Shared Sub ShowProperties(ByVal message As String, ByVal fileName As String) Console.WriteLine(message) ' Get the properties of the file Dim pdfFileObj As New PDFFile(fileName) pdfFileObj.Load() Dim props As PDFDocumentProperties = pdfFileObj.DocumentProperties 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) Console.WriteLine("----------:") End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void PDFFileExample() { string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD.pdf"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_14.pdf"); // Load the properties of the file ShowProperties("Source file", sourceFileName); // Update the properties of the file PDFFile file = new PDFFile(sourceFileName); file.DocumentProperties = new PDFDocumentProperties(); file.DocumentProperties.Author = "Me"; file.DocumentProperties.Title = "My title"; file.DocumentProperties.Subject = "My subject"; file.DocumentProperties.Creator = "My application"; file.DocumentProperties.Modified = DateTime.Now; file.SetDocumentProperties(destFileName); // Show the properties of the new file ShowProperties("Destination file", destFileName); } private static void ShowProperties(string message, string fileName) { Console.WriteLine(message); // Get the properties of the file PDFFile file = new PDFFile(fileName); file.Load(); PDFDocumentProperties props = file.DocumentProperties; 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); Console.WriteLine("----------:"); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2