SaveMode Enum
Lists save modes for documents that contain signatures.
Declaration
public enum SaveMode extends Enum<SaveMode> implements IIntEnum
Members
| Name | Description |
|---|---|
AUTO
|
If the document is loaded from a stream or channel and contains signatures or pending signatures, the API saves changes as an incremental update. Otherwise, the API rewrites the document. |
REWRITE
|
The API rewrites the entire document with all changes and then applies pending signatures. |
fromValue(int value)
|
Returns the |
getName()
|
Returns the name of the |
getValue()
|
Returns the integer value of the |
toString()
|
Returns the string representation of the |
valueOf(String name)
|
Returns the |
values()
|
Returns an array of all |
Remarks
Call the SaveOptions.getSaveMode() method to get the save mode. Call the SaveOptions.setSaveMode(value) method to specify how the API saves a document that contains signatures.
Refer to the following help topic for additional information: Sign PDF Documents — PDF Document API for Java.
Example
Sign a PDF Document and Rewrite the Entire Document
The following code snippet signs an existing signature field and rewrites the entire document:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = Files.newInputStream(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream certificateStream = Files.newInputStream(Path.of("certificate.pfx"))) {
if (pdfDocument.getFields().findByName("Signature1") instanceof SignatureField signatureField
&& !signatureField.getIsSigned()) {
SignatureOptions options = new SignatureOptions();
options.setCertificate(certificateStream, "CERTIFICATE_PASSWORD");
options.setReason("Approved");
pdfDocument.addSignature(signatureField, options);
SaveOptions saveOptions = new SaveOptions();
saveOptions.setSaveMode(SaveMode.REWRITE);
Files.createDirectories(Path.of("output"));
try (OutputStream outputStream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
pdfDocument.save(outputStream, saveOptions);
}
}
}
}
}