Edit in GitHubLog an issue

Protect PDF

Secure a PDF file with a password encrypt the document. Set an owner password and restrictions on certain features like printing, editing and copying in the PDF document to prevent end users from modifying it.

Support for AES-128 and AES-256 encryption on PDF files, with granular permissions for high and low quality printing and fill and sign form field restrictions.

Rest API

See our public API Reference for Protect PDF

Protect PDFs with user password

You can password protect PDFs so that only users with a document open password can open the file.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.protectpdf.ProtectPDF
public class ProtectPDF {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(ProtectPDF.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials.
ExecutionContext executionContext = ExecutionContext.create(credentials);
// Build ProtectPDF options by setting a User Password and Encryption
// Algorithm (used for encrypting the PDF file).
ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.passwordProtectOptionsBuilder()
.setUserPassword("encryptPassword")
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)
.build();
// Create a new operation instance.
ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.createNew(protectPDFOptions);
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/protectPDFInput.pdf");
protectPDFOperation.setInput(source);
// Execute the operation
FileRef result = protectPDFOperation.execute(executionContext);
// Save the result at the specified location
result.saveAs("output/protectPDFOutput.pdf");
} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}
}

Protect PDFs with owner password

You can secure a PDF file with owner/permissions password and set the restriction on certain features like printing, editing and copying in the PDF document. Refer to ContentEncryption and Permission in the API docs for a list of supported types of content to encrypt and types of document permissions.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.protectpdf.ProtectPDFWithOwnerPassword
public class ProtectPDFWithOwnerPassword {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(ProtectPDFWithOwnerPassword.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials.
ExecutionContext executionContext = ExecutionContext.create(credentials);
// Create new permissions instance and add the required permissions
Permissions permissions = Permissions.createNew();
permissions.addPermission(Permission.PRINT_LOW_QUALITY);
permissions.addPermission(Permission.EDIT_DOCUMENT_ASSEMBLY);
permissions.addPermission(Permission.COPY_CONTENT);
// Build ProtectPDF options by setting an Owner/Permissions Password, Permissions,
// Encryption Algorithm (used for encrypting the PDF file) and specifying the type of content to encrypt.
ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.passwordProtectOptionsBuilder()
.setOwnerPassword("password")
.setPermissions(permissions)
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)
.setContentEncryption(ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)
.build();
// Create a new operation instance.
ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.createNew(protectPDFOptions);
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/protectPDFInput.pdf");
protectPDFOperation.setInput(source);
// Execute the operation
FileRef result = protectPDFOperation.execute(executionContext);
// Save the result at the specified location
result.saveAs("output/protectPDFWithOwnerPasswordOutput.pdf");
} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.