Skip to main content

TdxPDFDocument.SaveToFile(string,Boolean,Boolean) Method

Saves the document to a file.

Declaration

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

Parameters

Name Type Description
AFileName string

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

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;

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