Remove Protection
Remove password security from a PDF document. This can only be accomplished with the owner password of the document which must be passed in the operation.
Rest API
See our public API Reference for Remove Protection
Remove security from PDFs
Use the below sample to remove security from a PDF document.
Please refer the API usage guide to understand how to use our APIs.
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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/removeProtectionInput.pdf").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2223 // Create parameters for the job24 RemoveProtectionParams removeProtectionParams = new RemoveProtectionParams("password");2526 // Creates a new job instance27 RemoveProtectionJob removeProtectionJob = new RemoveProtectionJob(asset, removeProtectionParams);2829 // Submit the job and gets the job result30 String location = pdfServices.submit(removeProtectionJob);31 PDFServicesResponse<RemoveProtectionResult> pdfServicesResponse = pdfServices.getJobResult(location, RemoveProtectionResult.class);3233 // Get content from the resulting asset(s)34 Asset resultAsset = pdfServicesResponse.getResult().getAsset();35 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3637 // Creates an output stream and copy stream asset's content to it38 Files.createDirectories(Paths.get("output/"));39 OutputStream outputStream = Files.newOutputStream(new File("output/removeProtectionOutput.pdf").toPath());40 LOGGER.info("Saving asset at output/removeProtectionOutput.pdf");41 IOUtils.copy(streamAsset.getInputStream(), outputStream);42 outputStream.close();43 } catch (IOException | ServiceApiException | SDKException | ServiceUsageException e) {44 LOGGER.error("Exception encountered while executing operation", e);45 }46 }47 }
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.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 // Create an ExecutionContext using credentials.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);2526 // Create a new operation instance27 RemoveProtectionOperation removeProtectionOperation = RemoveProtectionOperation.CreateNew();2829 // Set operation input from a source file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"removeProtectionInput.pdf");31 removeProtectionOperation.SetInput(sourceFileRef);3233 // Set the password for removing security from a PDF document.34 removeProtectionOperation.SetPassword("password");3536 // Execute the operation.37 FileRef result = removeProtectionOperation.Execute(executionContext);3839 // Save the result to the specified location.40 result.SaveAs(Directory.GetCurrentDirectory() + "/output/removeProtectionOutput.pdf");41 }42 catch (ServiceUsageException ex)43 {44 log.Error("Exception encountered while executing operation", ex);45 }46 // Catch more errors here . . .47 }4849 static void ConfigureLogging()50 {51 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());52 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));53 }54 }55 }56
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 .servicePrincipalCredentialsBuilder()11 .withClientId("PDF_SERVICES_CLIENT_ID")12 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")13 .build();1415 // Create an ExecutionContext using credentials16 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);1718 // Create a new operation instance.19 const removeProtectionOperation = PDFServicesSdk.RemoveProtection.Operation.createNew(),20 input = PDFServicesSdk.FileRef.createFromLocalFile(21 'resources/removeProtectionInput.pdf',22 PDFServicesSdk.RemoveProtection.SupportedSourceFormat.pdf23 );24 // Set operation input from a source file.25 removeProtectionOperation.setInput(input);2627 // Set the password for removing security from a PDF document.28 removeProtectionOperation.setPassword("password");2930 // Execute the operation and Save the result to the specified location.31 removeProtectionOperation.execute(executionContext)32 .then(result => result.saveAsFile('output/removeProtectionOutput.pdf'))33 .catch(err => {34 if(err instanceof PDFServicesSdk.Error.ServiceApiError35 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {36 console.log('Exception encountered while executing operation', err);37 } else {38 console.log('Exception encountered while executing operation', err);39 }40 });41 } catch (err) {42 console.log('Exception encountered while executing operation', err);43 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Remove-Protection34curl --location --request POST 'https://pdf-services.adobe.io/operation/removeprotection' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "password": "mypassword",10 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"11}'1213// Legacy API can be found here14// https://documentcloud.adobe.com/document-services/index.html#post-removeProtection