Skip to main content

TdxPDFDocument Class

A PDF document container.

Declaration

TdxPDFDocument = class(
    TObject
)

Remarks

The TdxPDFDocument class implements a document container with an API for core content management functionality, such as load and save operations with support for encryption as well as digital signatures, content search and export, etc.

The PDF Viewer control relies on a TdxPDFDocument class instance to load, store, and manage documents. You can use create a TdxPDFDocument class instance as a standalone document container for PDF document management without user interaction.

Main API Members

The list below outlines key members of the TdxPDFDocument class. These members allow you to load, parse, modify, and save PDF documents.

AllowContentExtraction | AllowPrinting

Return user action permissions in the current document if it is loaded with a user password.

Tip

You can use the SecurityOptions.Permissions property to obtain other user permissions for password-protected documents.

FileAttachments

Provides access to document file attachments.

You can use this property to add, remove, or save file attachments.

FindText
Searches specified text occurrences in the current document.
Form
Provides access to the current document’s interactive form.
Information
Allows you to read and edit document metadata.
OnSearchProgress
Allows you to track the current search position.
PageCount
Returns the number of pages in the current document.
PageInfo
Allows you to obtain information on individual document pages and copy their content.

Document Structure Management

Append
Merge two PDF documents.
OnChanged
Allows you to track document changes.
Pages
Allows you to add, insert, rearrange, rotate, and delete individual document pages.

Import and Export

LoadFromFile | LoadFromStream
Allow you to load a PDF document from a file or stream.
OnGetPassword
Allows you to specify a user or owner password in code when the container loads a password-protected PDF document.
OnLoaded
Notifies the application of a successful document load operation.
OnSaveProgress
Allows you to track document save progress.
PasswordAttemptsLimit
Specifies the number of allowed attempts to load an encrypted PDF document.
SecurityOptions | SignatureOptions
Allow you to encrypt the current document, enable password protection, and add a digital signature before a save operation.
SaveToFile | SaveToStream
Allow you to save the current document to a file or stream according to the current digital signature and user permission settings.

General-Purpose API Members

BeginUpdate | EndUpdate
Allow you to avoid excessive notifications and improve performance during batch changes.
Clear
Unloads the current document.
OnUnloaded
Allows you to respond to a document unload operation.

Code Example: Delete the First Two Document Pages

The following code example loads a PDF document from the Demo.pdf file, deletes the first two pages of the loaded document, and saves the resulting document to a different file (Result.pdf):

uses
  dxPDFDocument;  // This unit declares the TdxPDFDocument class
// ...
var
  ADocument: TdxPDFDocument;
begin
  ADocument := TdxPDFDocument.Create;
  try
    ADocument.LoadFromFile('Data\Demo.pdf');
    ADocument.BeginUpdate;  // Initiates the following batch change
    try
      ADocument.Pages.Delete(0);
      ADocument.Pages.Delete(0);
    finally
      ADocument.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
    end;
    ADocument.SaveToFile('Data\Result.pdf');
  finally
    ADocument.Free;  // Releases the created document container to avoid memory leaks
  end;

Direct TdxPDFDocument Class Reference

The TdxPDFCustomViewer.Document property references a TdxPDFDocument object.

Inheritance

TObject
TdxPDFDocument
See Also