Skip to main content

PdfDocument

Version: 12.0

cete.dynamicpdf.merger.pdfdocument

PdfDocument​

Represents a PDF document for import.

public class PdfDocument
Public Class PdfDocument

Inheritance: Object → PdfDocument

Licensing Info​

This class is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Examples​

The following example will first merge two entire PDF documents together, then will Append a selected page of a third PDF to the end.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Merger

Module MyModule

Sub Main()

' Create two PDF document objects
Dim pdfA As PdfDocument = New PdfDocument("C:\ImportPDF.pdf")
' The owner's password is required to merge encrypted PDFs
Dim pdfB As PdfDocument = New PdfDocument("C:\EncryptedPDF.pdf", "owner")

' Merge the two documents
Dim MyDocument As MergeDocument = MergeDocument.Merge(pdfA, pdfB)

' Append an additional document
Dim pdfC As PdfDocument = New PdfDocument("C:\MyDocumentC.pdf")
MyDocument.Append(pdfC, 2, 1)

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")

End Sub
End Module
using System;
using ceTe.DynamicPDF.Merger;
Public Class Example
{
public static void CreatePDF(string outputPath, string inputPathPdfA, string inputPathPdfB, string password, string inputPathPdfC, int startPage)
{
// Create two PDF document objects
PdfDocument pdfA = new PdfDocument(inputPathPdfA);
// The owner's password is required to merge encrypted PDFs
PdfDocument pdfB = new PdfDocument(inputPathPdfB, password);

// Merge the two documents
MergeDocument document = MergeDocument.Merge(pdfA, pdfB);

// Append an additional document
PdfDocument pdfC = new PdfDocument(inputPathPdfC);
document.Append(pdfC, startPage, 1);

// Save the PDF
document.Draw(outputPath);
}
}

Remarks​

This class should be used when you will be referencing an existing PDF document more than once. Using a PDFDocument is more efficient than specifying a file path because the document will not need to be parsed again on each subsequent reference. This class is safe for multithreaded operations.

Constructors​

PdfDocument(Byte[])​

Initializes a new instance of the PdfDocument class.

public PdfDocument(Byte[] data)
Public Sub New (data As Byte())

Parameters​

A byte array containing the PDF document data.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

PdfDocument(Byte[], String)​

Initializes a new instance of the PdfDocument class.

public PdfDocument(Byte[] data, string password)
Public Sub New (data As Byte(), password As String)

Parameters​

A byte array containing the PDF document data.

Owner password of the encrypted PDF document.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

PdfDocument(Stream)​

Initializes a new instance of the PdfDocument class.

public PdfDocument(Stream stream)
Public Sub New (stream As Stream)

Parameters​

Stream object containing the PDF document data.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

PdfDocument(Stream, String)​

Initializes a new instance of the PdfDocument class.

public PdfDocument(Stream stream, string password)
Public Sub New (stream As Stream, password As String)

Parameters​

Stream object containing the PDF document data.

Owner password of the encrypted PDF document.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

PdfDocument(String)​

Initializes a new instance of the PdfDocument class.

public PdfDocument(string filePath)
Public Sub New (filePath As String)

Parameters​

Physical file path of the PDF document.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

PdfDocument(String, String)​

Initializes a new instance of the PdfDocument class.

public PdfDocument(string filePath, string password)
Public Sub New (filePath As String, password As String)

Parameters​

Physical file path of the PDF document.

Owner password of the encrypted PDF document.

Licensing Info​

This constructor is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Exceptions​

PdfParsingException The PDF file cannot be parsed because it is likely corrupt or invalid.

PdfSecurityException The PDF file cannot be read because it is encrypted and the owner password is incorrect or not supplied.

Properties​

Author​

Gets the author property of the PDF document.

public string Author { get; }
Public Property Author As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

CollectionType​

Gets a value indicating the collectionType of a Pdf document

public CollectionType CollectionType { get; set; }
Public Property CollectionType As CollectionType

Property Value​

CollectionType

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Creator​

Gets the creator property of the PDF document.

public string Creator { get; }
Public Property Creator As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

CustomProperties​

Gets the custom properties of the PDF document.

public Dictionary&ltstring, string> CustomProperties { get; }
Public Property CustomProperties As Dictionary(Of String, Of String)

Property Value​

Dictionary&ltstring, string>

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Form​

Gets the AcroForm for the document.

public PdfForm Form { get; }
Public Property Form As PdfForm

Property Value​

PdfForm

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Keywords​

Gets the keywords property of the PDF document.

public string Keywords { get; }
Public Property Keywords As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

NeedsRendering​

Get the Needs Rendering property of the PDF document.

public bool NeedsRendering { get; }
Public Property NeedsRendering As Boolean

Property Value​

Boolean

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Outlines​

Gets the outlines of the PDF document.

public PdfOutlineList Outlines { get; }
Public Property Outlines As PdfOutlineList

Property Value​

PdfOutlineList

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Pages​

Gets a collection of PDF pages for the document.

public PdfPageList Pages { get; }
Public Property Pages As PdfPageList

Property Value​

PdfPageList

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Producer​

Gets the producer property of the PDF document.

public string Producer { get; }
Public Property Producer As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

SecurityInfo​

Gets the security type of the PDF document.

public SecurityInfo SecurityInfo { get; }
Public Property SecurityInfo As SecurityInfo

Property Value​

SecurityInfo

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Signed​

Gets the signed property of the PDF document (only available in version 10.27+).

public bool Signed { get; }
Public Property Signed As Boolean

Property Value​

Boolean

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Remarks​

This property is only available with version 10.27 and later.

Subject​

Gets the subject property of the PDF document.

public string Subject { get; }
Public Property Subject As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Tagged​

Gets the Taging property of the PDF document.

public bool Tagged { get; }
Public Property Tagged As Boolean

Property Value​

Boolean

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Title​

Gets the title property of the PDF document.

public string Title { get; }
Public Property Title As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

XmpMetadata​

Gets the xml metadata string.

public string XmpMetadata { get; }
Public Property XmpMetadata As String

Property Value​

String

Licensing Info​

This property is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Methods​

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Get3DImages()​

Returns an array of ImageInformation3D objects of all the 3D images present in the document.

public ImageInformation3D[] Get3DImages()
Function Get3DImages() As ImageInformation3D[]

Returns​

An array of ImageInformation3D objects of all the 3D images present in the document.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Remarks​

This method returns 3D image information only when the license key is applied and it will not work in evaluation mode.

GetAttachments()​

Retrieves the attachment files in the PDF document.

public Attachment[] GetAttachments()
Function GetAttachments() As Attachment[]

Returns​

Contains the list of attachment files present in the pdf.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetCreationDate()​

Gets the creation date of the PDF document.

public Nullable&ltDateTime> GetCreationDate()
Function GetCreationDate() As Nullable(Of Date)

Returns​

Returns the DateTime structure, having creation date in UTC time.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Exceptions​

Throws merger exception if wrong datetime format specified.

GetEncryptionInfo(Byte[])​

Gets the security information of the given PDF document.

public static EncryptionInfo GetEncryptionInfo(Byte[] data)
Shared Function GetEncryptionInfo(data As Byte()) As EncryptionInfo

Parameters​

A byte array containing the PDF document data.

Returns​

The security information of the given PDF document.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetEncryptionInfo(String)​

Gets the security information of the given PDF document.

public static EncryptionInfo GetEncryptionInfo(string filePath)
Shared Function GetEncryptionInfo(filePath As String) As EncryptionInfo

Parameters​

Physical file path of the PDF document.

Returns​

The security information of the given PDF document.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetFonts()​

Gets the informaton of all the fonts present in a document.

public FontInformation[] GetFonts()
Function GetFonts() As FontInformation[]

Returns​

An array of FontInformation .

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetImages()​

Returns an array of ImageInformation objects of all the images present in the document.

public ImageInformation[] GetImages()
Function GetImages() As ImageInformation[]

Returns​

An array of ImageInformation objects of all the images present in the document.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Examples​

The following example will extract the images in the given PDF document.

Imports System
Imports System.IO
Imports ceTe.DynamicPDF.Merger

Module MyModule

Sub Main()

' Create PDF document object
Dim pdfA As PdfDocument = New PdfDocument( "C:\Input.pdf")

' Call GetText method from PDF document object to get the text from the document
Dim imageInfoList As ImageInformation() = pdfA.GetImages() For i As Integer = 0 To imageInfoList.Length - 1 Dim extractedImageData As ExtractedImageData = imageInfoList(i).GetImage() Dim data As Byte() = Nothing Dim extension As String = ""
If extractedImageData.ExtractedImageType = ExtractedImageType.Png Then extension = ".png" Else extension = ".jpg" End If
data = extractedImageData.Data File.WriteAllBytes("C:\Output\image" & i & extension, data)
Next

End Sub
End Module
using System;
using System.IO;
using ceTe.DynamicPDF.Merger;

Public Class Example
{
public static void GetImages(string inputPath, string outputPath)
{
// Create PDF document object
PdfDocument pdfA = new PdfDocument(inputPath);

// Call GetImages method from PDF document object to get the images from the document
ImageInformation[] imageInfoList = pdf.GetImages();
for (int i = 0; i < imageInfoList.Length; i++)
{
ExtractedImageData extractedImageData = imageInfoList[i].GetImage();
byte[] data = null;
string extension = "";
if (extractedImageData.ExtractedImageType == ExtractedImageType.Png)
extension = ".png";
else
extension = ".jpg";
data = extractedImageData.Data;
File.WriteAllBytes(outputPath + i + extension, data);
}
}
}

Remarks​

This method returns image information only when the license key is applied and it will not work in evaluation mode.

GetModifiedDate()​

Gets the modified date of the PDF document.

public Nullable&ltDateTime> GetModifiedDate()
Function GetModifiedDate() As Nullable(Of Date)

Returns​

Returns the DateTime structure, having modified date in UTC time.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Exceptions​

Throws merger exception if wrong datetime format specified.

GetPage(Int32)​

Gets a page by page number.

public PdfPage GetPage(int pageNumber)
Function GetPage(pageNumber As Integer) As PdfPage

Parameters​

The page number to retrieve.

Returns​

A PdfPage object.

Licensing Info​

This method is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

Remarks​

The first page is 1.

GetSecurityStore()​

Gets the Document Security Store (DSS) of the Pdf document.

public SecurityStore GetSecurityStore()
Function GetSecurityStore() As SecurityStore

Returns​

Returns SecurityStore object

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetSignedSignatureFields()​

Gets the list of PdfSignatureField that are present in the document.

public List&ltPdfSignatureField> GetSignedSignatureFields()
Function GetSignedSignatureFields() As List(Of PdfSignatureField)

Returns​

Returns a list of PdfSignatureField objects

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Examples​

Following example verifies the signature present in a document.

Module Example
Sub SignVerify(sourcePdfFilePath as string) 'Create a PdfDocument object using the source PDF that is being verified for signatures
Dim pdfDocument As PdfDocument = New PdfDocument(sourcePdfFilePath) 'Get the list of PdfSignatureField from the pdf document
Dim signedSignatures As List(Of PdfSignatureField) = pdfDocument.GetSignedSignatureFields() 'Get the Document Security Store (DSS) that contains the security and signature validation related information
Dim dss As SecurityStore = pdfDocument.GetSecurityStore()
'Method that validates the first field in the signedSignatures
ProcessPkcsSignatureContents(fileName, signedSignatures(0))
End Sub

Sub ProcessPkcsSignatureContents(fileName As String, pdfSignatureField As PdfSignatureField) 'Get the content that is signed using the selected signature field
Dim signatureContent As Byte() = pdfSignatureField.SignatureContent
'Create a byte array to hold the data that is present in the signature range
Dim dataToVerify As Byte() = New Byte(pdfSignatureField.Range(0).Length + pdfSignatureField.Range(1).Length) 'Get all the PDF file data that is being validated
Dim fileData As Byte() = File.ReadAllBytes(fileName) 'Load the dataToVerify from the PDF, using the range of the signature
Array.Copy(fileData, dataToVerify, pdfSignatureField.Range(0).Length)
Array.Copy(fileData, pdfSignatureField.Range(1).StartIndex, dataToVerify, pdfSignatureField.Range(0).Length, pdfSignatureField.Range(1).Length)
'Create a ContentInfo object using the data to be verified Dim contentInfo As ContentInfo = New ContentInfo(dataToVerify) 'Create a SignedCms object using contentInfo
Dim signedCms As SignedCms = New SignedCms(contentInfo, True)
'Decode the signature content signedCms.Decode(signatureContent)
'Verify the signature. This method will throw an exception if the data is invalid for the given signature. signedCms.CheckSignature(False)
End Sub
End Module
using ceTe.DynamicPDF.Merger;
using System;
using System.IO;
using System.Security.Cryptography.Pkcs;

class Examples
{
public static void SignVerify(string sourcePdfFilePath)
{
// Create a PdfDocument object using the source PDF that is being verified for signatures
PdfDocument pdfDocument = new PdfDocument(sourcePdfFilePath);

// Get the list of PdfSignatureField from the pdf document
var signedSignatures = pdfDocument.GetSignedSignatureFields();

// Get the Document Security Store (DSS) that contains the security and signature validation related information
var dss = pdfDocument.GetSecurityStore();

// Method that validates the first field in the signedSignatures
ProcessPkcsSignatureContents(sourcePdfFilePath, signedSignatures[0]);
}

private static void ProcessPkcsSignatureContents(string fileName, ceTe.DynamicPDF.Merger.Forms.PdfSignatureField pdfSignatureField)
{
// Get the content that is signed using the selected signature field
byte[] signatureContent = pdfSignatureField.SignatureContent;

// Create a byte array to hold the data that is present in the signature range
byte[] dataToVerify = new byte[pdfSignatureField.Range[0].Length + pdfSignatureField.Range[1].Length];

// Get all the PDF file data that is being validated
byte[] fileData = File.ReadAllBytes(fileName);

// Load the dataToVerify from the PDF, using the range of the signature
Array.Copy(fileData, dataToVerify, pdfSignatureField.Range[0].Length);
Array.Copy(fileData, pdfSignatureField.Range[1].StartIndex, dataToVerify, pdfSignatureField.Range[0].Length, pdfSignatureField.Range[1].Length);

// Create a ContentInfo object using the data to be verified
ContentInfo contentInfo = new ContentInfo(dataToVerify);

// Create a SignedCms object using contentInfo
SignedCms signedCms = new SignedCms(contentInfo, true);

// Decode the signature content
signedCms.Decode(signatureContent);

// Verify the signature. This method will throw an exception if the data is invalid for the given signature.
signedCms.CheckSignature(false);
}
}

GetText()​

Gets the text in all the pages.

public string GetText()
Function GetText() As String

Returns​

A string containing the text in all the pages.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Examples​

The following example will extract the entire text in the given PDF documents.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Merger

Module MyModule

Sub Main()

' Create PDF document object
Dim pdfA As PdfDocument = New PdfDocument( "C:\TimeMachine.pdf")

' Call GetText method from PDF document object to get the text from the document
Dim extractedText As String = pdfA.GetText()

End Sub
End Module
using System;
using ceTe.DynamicPDF.Merger;

Public Class Example
{
public static void GetText(string inputPath)
{
// Create PDF document object
PdfDocument pdfA = new PdfDocument(inputPath);

// Call GetText method from PDF document object to get the text from the document
string extractedText = pdfA.GetText();
}
}

Remarks​

This method can be used to extract the text in the same order the pdf operators are loaded. Text extraction skips characters that are morethan 2 bytes. With some of the .Net runtimes (example: .Net Core 2.0), Text extraction will give the error "No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.". To resolve this error refer the user manual page Encoding Considerations.

GetText(TextExtractionOrder)​

Gets the text in all the pages.

public string GetText(TextExtractionOrder textExtractionOrder)
Function GetText(textExtractionOrder As TextExtractionOrder) As String

Parameters​

Order in which text has to be extracted.

Returns​

A string containing the text in all the pages.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Examples​

The following example will extract the entire text in the given PDF documents.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Merger

Module MyModule

Sub Main()

' Create PDF document object
Dim pdfA As PdfDocument = New PdfDocument( "C:\TimeMachine.pdf")

' Call GetText method from PDF document object to get the text from the document
Dim extractedText As String = pdfA.GetText(TextExtractionOrder.Visible)

End Sub
End Module
using System;
using ceTe.DynamicPDF.Merger;

Public Class Example
{
public static void GetText(string inputPath)
{
// Create PDF document object
PdfDocument pdfA = new PdfDocument(inputPath);

// Call GetText method from PDF document object to get the text from the document
string extractedText = pdfA.GetText(TextExtractionOrder.Visible);
}
}

Remarks​

This method can be used to extract the text in the same order the pdf operators are loaded. Text extraction skips characters that are morethan 2 bytes. With some of the .Net runtimes (example: .Net Core 2.0), Text extraction will give the error "No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.". To resolve this error refer the user manual page Encoding Considerations.

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

GetXfaInfo()​

Gets the type of XFA in the given PDF document.

public XfaInfo GetXfaInfo()
Function GetXfaInfo() As XfaInfo

Returns​

The type of XfaInfo present in the given PDF document.

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

SetDocumentInfo(Document)​

Sets the document info on the supplied Document to match this document.

public void SetDocumentInfo(Document document)
Sub SetDocumentInfo(document As Document)

Parameters​

A document to set.

Licensing Info​

This method is a DynamicPDF Core Suite Essentials feature. One of the following is required for non-evaluation usage:

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

Licensing Info​

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

See Also​

ceTe.DynamicPDF.Merger