public class ProtectPDFOperation extends Object implements Operation
The supported algorithm for encrypting the PDF contents are listed here. The EncryptionAlgorithm
enum can be used to set the
encryption algorithm.
For AES-128 encryption the user password supports ASCII characters only; allowed minimum length of password is 6 characters and maximum length of password is 32 characters. For AES-256 encryption the user password supports Unicode character set and the maximum length of password is 127 UTF-8 bytes.
Sample Usage:
ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.passwordProtectOptionsBuilder()
.setUserPassword("mypassword")
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_128)
.build();
ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.createNew(protectPDFOptions);
protectPDFOperation.setInput(FileRef.createFromLocalFile("~/Documents/protectOperationInput.pdf",
ProtectPDFOperation.SupportedSourceFormat.PDF.getMediaType()));
Credentials credentials = Credentials.serviceAccountCredentialsBuilder().fromFile("pdftools-api-credentials.json").build();
FileRef result = protectPDFOperation.execute(ExecutionContext.create(credentials));
result.saveAs("output/protectOperationOutput.pdf");
Modifier and Type | Class and Description |
---|---|
static class |
ProtectPDFOperation.SupportedSourceFormat
Supported source file formats for
ProtectPDFOperation . |
Modifier and Type | Method and Description |
---|---|
static ProtectPDFOperation |
createNew(ProtectPDFOptions protectPDFOptions)
Constructs a
ProtectPDFOperation instance. |
FileRef |
execute(ExecutionContext context)
Executes this operation synchronously using the supplied context and returns a new FileRef instance for the resulting PDF file.
|
void |
setInput(FileRef sourceFileRef)
Sets an input file.
|
public static ProtectPDFOperation createNew(ProtectPDFOptions protectPDFOptions)
ProtectPDFOperation
instance.protectPDFOptions
- options for setting User Password (used for encrypting PDF); Cannot be nullProtectPDFOperation
instancepublic void setInput(FileRef sourceFileRef)
sourceFileRef
- an input file; can not be nullpublic FileRef execute(ExecutionContext context) throws ServiceApiException, IOException, ServiceUsageException
The resulting file may be stored in the system temporary directory (per java.io.tmpdir System property).
See FileRef
for how temporary resources are cleaned up.
execute
in interface Operation
context
- the context in which to execute the operationServiceApiException
- if an API call results in an error responseIOException
- if there is an error in reading either the input source or the resulting PDF fileServiceUsageException
- if service usage limits have been reached or credentials quota has been exhaustedCopyright © 2020 Adobe. All rights reserved.