public class ProtectPDFOperation extends Object implements Operation
The supported algorithm for encrypting the PDF document are listed here. The EncryptionAlgorithm
enum can be used to set the
encryption algorithm.
For AES-128 encryption the password supports LATIN-I characters only. For AES-256 encryption the password supports Unicode character set.
Sample Usage:
Permissions permissions = Permissions.createNew();
permissions.addPermission(Permission.PRINT_LOW_QUALITY);
permissions.addPermission(Permission.EDIT_DOCUMENT_ASSEMBLY);
permissions.addPermission(Permission.COPY_CONTENT);
ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.passwordProtectOptionsBuilder()
.setUserPassword("openpassword")
.setOwnerPassword("permissionspassword")
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_128)
.setContentEncryption(ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)
.setPermissions(permissions)
.build();
ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.createNew(protectPDFOptions);
protectPDFOperation.setInput(FileRef.createFromLocalFile("~/Documents/protectOperationInput.pdf",
ProtectPDFOperation.SupportedSourceFormat.PDF.getMediaType()));
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.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 securing PDF file with password(s); 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 © 2023 Adobe. All rights reserved.