Remove Protection
Remove security from PDFs
Use the below sample to remove security from a PDF document.
Java
.NET
Node JS
REST API
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.removeprotection.RemoveProtection45 public class RemoveProtection {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(RemoveProtection.class);910 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();1617 // Create an ExecutionContext using credentials and create a new operation instance.18 ExecutionContext executionContext = ExecutionContext.create(credentials);19 RemoveProtectionOperation removeProtectionOperation = RemoveProtectionOperation.createNew();2021 // Set operation input from a source file.22 FileRef source = FileRef.createFromLocalFile("src/main/resources/removeProtectionInput.pdf");23 removeProtectionOperation.setInput(source);2425 // Set the password for removing security from a PDF document.26 removeProtectionOperation.setPassword("password");2728 // Execute the operation.29 FileRef result = removeProtectionOperation.execute(executionContext);3031 // Save the result to the specified location.32 result.saveAs("output/removeProtectionOutput.pdf");3334 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {35 LOGGER.error("Exception encountered while executing operation", e);36 }37 }38 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd RemoveProtection/4// dotnet run RemoveProtection.csproj56 namespace RemoveProtection7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServiceAccountCredentialsBuilder()19 .FromFile(Directory.GetCurrentDirectory() + "/pdfservices-api-credentials.json")20 .Build();2122 // Create an ExecutionContext using credentials.23 ExecutionContext executionContext = ExecutionContext.Create(credentials);2425 // Create a new operation instance26 RemoveProtectionOperation removeProtectionOperation = RemoveProtectionOperation.CreateNew();2728 // Set operation input from a source file.29 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"removeProtectionInput.pdf");30 removeProtectionOperation.SetInput(sourceFileRef);3132 // Set the password for removing security from a PDF document.33 removeProtectionOperation.SetPassword("password");3435 // Execute the operation.36 FileRef result = removeProtectionOperation.Execute(executionContext);3738 // Save the result to the specified location.39 result.SaveAs(Directory.GetCurrentDirectory() + "/output/removeProtectionOutput.pdf");40 }41 catch (ServiceUsageException ex)42 {43 log.Error("Exception encountered while executing operation", ex);44 }45 // Catch more errors here . . .46 }4748 static void ConfigureLogging()49 {50 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());51 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));52 }53 }54 }55
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/removeprotection/remove-protection.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .serviceAccountCredentialsBuilder()11 .fromFile("pdfservices-api-credentials.json")12 .build();1314 // Create an ExecutionContext using credentials15 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);1617 // Create a new operation instance.18 const removeProtectionOperation = PDFServicesSdk.RemoveProtection.Operation.createNew(),19 input = PDFServicesSdk.FileRef.createFromLocalFile(20 'resources/removeProtectionInput.pdf',21 PDFServicesSdk.RemoveProtection.SupportedSourceFormat.pdf22 );23 // Set operation input from a source file.24 removeProtectionOperation.setInput(input);2526 // Set the password for removing security from a PDF document.27 removeProtectionOperation.setPassword("password");2829 // Execute the operation and Save the result to the specified location.30 removeProtectionOperation.execute(executionContext)31 .then(result => result.saveAsFile('output/removeProtectionOutput.pdf'))32 .catch(err => {33 if(err instanceof PDFServicesSdk.Error.ServiceApiError34 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {35 console.log('Exception encountered while executing operation', err);36 } else {37 console.log('Exception encountered while executing operation', err);38 }39 });40 } catch (err) {41 console.log('Exception encountered while executing operation', err);42 }
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-removeProtection34curl --location --request POST 'https://cpf-ue1.adobe.io/ops/:create?respondWith=%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D' \5--header 'Authorization: Bearer {{Placeholder for token}}' \6--header 'Accept: application/json, text/plain, */*' \7--header 'x-api-key: {{Placeholder for client_id}}' \8--header 'Prefer: respond-async,wait=0' \9--form 'contentAnalyzerRequests="{10 \"cpf:inputs\": {11 \"params\": {12 \"cpf:inline\": {13 \"password\": \"password\"14 }15 },16 \"documentIn\": {17 \"cpf:location\": \"InputFile0\",18 \"dc:format\": \"application/pdf\"19 }20 },21 \"cpf:engine\": {22 \"repo:assetId\": \"urn:aaid:cpf:Service-d80dc37d3aee44a8839e3429360db9a7\"23 },24 \"cpf:outputs\": {25 \"documentOut\": {26 \"cpf:location\": \"multipartLabelOut\",27 \"dc:format\": \"application/pdf\"28 }29 }30}"' \31--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'