Back to Devexpress

TdxPDFDocument.SaveToFile(string,Boolean,Boolean) Method

vcl-dxpdfdocument-dot-tdxpdfdocument-dot-savetofile-x28-system-dot-string-system-dot-boolean-system-dot-boolean-x29.md

latest5.9 KB
Original Source

TdxPDFDocument.SaveToFile(string,Boolean,Boolean) Method

Saves the document to a file.

Declaration

delphi
procedure SaveToFile(const AFileName: string; AAllowSignatureRemoval: Boolean = False; AResetModified: Boolean = True);

Parameters

NameTypeDescription
AFileNamestring

An absolute or relative path to the target file.

| | AAllowSignatureRemoval | Boolean |

Optional. If True, the procedure removes all digital signatures that the document already has.

If you omit this parameter, the procedure raises an exception if the document has one or more digital signatures.

| | AResetModified | Boolean |

Optional. If True, the procedure resets the Modified property to False.

|

Remarks

Call LoadFromFile and SaveToFile procedures to load and save PDF documents. A SaveToStream procedure call raises the OnSaveProgress event multiple times, every time certain PDF objects in the document are successfully saved. The number of event occurrences depends on the size and complexity of the document.

Add a Digital Signature

A SaveToFile procedure call adds one digital signature to the resulting PDF file if the following conditions are met:

Refer to the TdxPDFSignatureOptions class description for detailed information on available options.

Enforce Password Protection

A SaveToFile procedure call encrypts the document and adds password protection if the following conditions are met:

Refer to the TdxPDFSecurityOptions class description for detailed information on available options.

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
  }

Limitations

Existing Digital Signatures

The SaveToFile procedure cannot save a document with multiple digital signatures or preserve an existing signature. If the source document has one or more digital signatures, a SaveToFile procedure call raises the EdxPDFException exception that shows the following message:

“The document has a digital signature and cannot be saved. To remove the signature and save the document, call the method again and pass True as the AAllowSignatureRemoval parameter.”

Follow the instructions in the message to avoid this exception and save the document without imported digital signatures.

AES Encryption

The current SaveToFile procedure implementation cannot use the AES encryption algorithm to protect a document and raises the EdxPDFEncryptionException exception when the following conditions are met:

Note

LoadFromFile and LoadFromStream procedures can load documents encrypted with the AES algorithm.

See Also

TdxPDFDocument.SaveToStream Procedure

TdxPDFDocument Class

TdxPDFDocument Members

dxPDFDocument Unit