Edit in GitHubLog an issue

Remove Protection

Remove security from PDFs

Use the below sample to remove security from a PDF document.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.removeprotection.RemoveProtection
4
5 public class RemoveProtection {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(RemoveProtection.class);
9
10 public static void main(String[] args) {
11 try {
12 // Initial setup, create credentials instance.
13 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
14 .fromFile("pdfservices-api-credentials.json")
15 .build();
16
17 // Create an ExecutionContext using credentials and create a new operation instance.
18 ExecutionContext executionContext = ExecutionContext.create(credentials);
19 RemoveProtectionOperation removeProtectionOperation = RemoveProtectionOperation.createNew();
20
21 // Set operation input from a source file.
22 FileRef source = FileRef.createFromLocalFile("src/main/resources/removeProtectionInput.pdf");
23 removeProtectionOperation.setInput(source);
24
25 // Set the password for removing security from a PDF document.
26 removeProtectionOperation.setPassword("password");
27
28 // Execute the operation.
29 FileRef result = removeProtectionOperation.execute(executionContext);
30
31 // Save the result to the specified location.
32 result.saveAs("output/removeProtectionOutput.pdf");
33
34 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
35 LOGGER.error("Exception encountered while executing operation", e);
36 }
37 }
38 }
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.