vcl-dxpdfdocument-dot-tdxpdfdocument-dot-savetofile-x28-system-dot-string-system-dot-boolean-system-dot-boolean-x29.md
Saves the document to a file.
procedure SaveToFile(const AFileName: string; AAllowSignatureRemoval: Boolean = False; AResetModified: Boolean = True);
| 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.
|
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.
A SaveToFile procedure call adds one digital signature to the resulting PDF file if the following conditions are met:
True.Refer to the TdxPDFSignatureOptions class description for detailed information on available options.
A SaveToFile procedure call encrypts the document and adds password protection if the following conditions are met:
True.Refer to the TdxPDFSecurityOptions class description for detailed information on available options.
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; // 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;
#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
}
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.
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:
True.Note
LoadFromFile and LoadFromStream procedures can load documents encrypted with the AES algorithm.
See Also