Back to Devexpress

TdxPDFDocument.LoadFromFile(string) Method

vcl-dxpdfdocument-dot-tdxpdfdocument-dot-loadfromfile-x28-system-dot-string-x29.md

latest3.5 KB
Original Source

TdxPDFDocument.LoadFromFile(string) Method

Loads a PDF document from the specified file.

Declaration

delphi
procedure LoadFromFile(const AFileName: string);

Parameters

NameTypeDescription
AFileNamestring

An absolute or relative path to the source file.

|

Remarks

Call LoadFromFile and SaveToFile procedures to load and save PDF documents.

A successful document load operation resets the Modified property to False. To clear the document container, call the Clear procedure.

Load Password-Protected Documents

If the source document is protected with a password, a LoadFromFile procedure call invokes the Enter Password dialog to prompt a user to enter a user or owner password.

Tip

You can handle the OnGetPassword event to specify the required password without user interaction.

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):

delphi
uses
  dxPDFDocument; // 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;
cpp
#include "dxPDFDocument.hpp" // Declares the TdxPDFDocument class
// ...
  TdxPDFDocument *ADocument = new TdxPDFDocument();
  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
    }
    ADocument->SaveToFile("Data\\Result.pdf");
  }
  __finally
  {
    delete ADocument; // Releases the created document container to avoid memory leaks
  }

See Also

TdxPDFDocument.LoadFromStream Procedure

TdxPDFCustomViewer.LoadFromFile Procedure

TdxPDFCustomViewer.LoadFromStream Procedure

TdxPDFDocument Class

TdxPDFDocument Members

dxPDFDocument Unit