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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/protectPDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));
// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);
// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
// Create parameters for the job
ProtectPDFParams protectPDFParams = ProtectPDFParams.passwordProtectOptionsBuilder()
.setUserPassword("password")
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)
.build();
// Creates a new job instance
ProtectPDFJob protectPDFJob = new ProtectPDFJob(asset, protectPDFParams);
// Submit the job and gets the job result
String location = pdfServices.submit(protectPDFJob);
PDFServicesResponse<ProtectPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ProtectPDFResult.class);
// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);
// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/protectPDFOutput.pdf").toPath());
LOGGER.info("Saving asset at output/protectPDFOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} 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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/protectPDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));
// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);
// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
// 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);
// Create parameters for the job
ProtectPDFParams protectPDFParams = ProtectPDFParams.passwordProtectOptionsBuilder()
.setOwnerPassword("password")
.setPermissions(permissions)
.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)
.setContentEncryption(ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)
.build();
// Creates a new job instance
ProtectPDFJob protectPDFJob = new ProtectPDFJob(asset, protectPDFParams);
// Submit the job and gets the job result
String location = pdfServices.submit(protectPDFJob);
PDFServicesResponse<ProtectPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ProtectPDFResult.class);
// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);
// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/protectPDFWithOwnerPasswordOutput.pdf").toPath());
LOGGER.info("Saving asset at output/protectPDFWithOwnerPasswordOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} 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.