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 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.protectpdf.ProtectPDF45 public class ProtectPDF {6 // Initialize the logger.7 private static final Logger LOGGER = LoggerFactory.getLogger(ProtectPDF.class);89 public static void main(String[] args) {1011 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/protectPDFInput.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 ProtectPDFParams protectPDFParams = ProtectPDFParams.passwordProtectOptionsBuilder()25 .setUserPassword("password")26 .setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)27 .build();2829 // Creates a new job instance30 ProtectPDFJob protectPDFJob = new ProtectPDFJob(asset, protectPDFParams);3132 // Submit the job and gets the job result33 String location = pdfServices.submit(protectPDFJob);34 PDFServicesResponse<ProtectPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ProtectPDFResult.class);3536 // Get content from the resulting asset(s)37 Asset resultAsset = pdfServicesResponse.getResult().getAsset();38 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3940 // Creates an output stream and copy stream asset's content to it41 Files.createDirectories(Paths.get("output/"));42 OutputStream outputStream = Files.newOutputStream(new File("output/protectPDFOutput.pdf").toPath());43 LOGGER.info("Saving asset at output/protectPDFOutput.pdf");44 IOUtils.copy(streamAsset.getInputStream(), outputStream);45 outputStream.close();46 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {47 LOGGER.error("Exception encountered while executing operation", ex);48 }49 }50 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ProtectPDF/4// dotnet run ProtectPDF.csproj56 namespace ProtectPDF7 {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 // Build ProtectPDF options by setting a User Password and Encryption27 // Algorithm (used for encrypting the PDF file).28 ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.PasswordProtectOptionsBuilder()29 .SetUserPassword("encryptPassword")30 .SetEncryptionAlgorithm(EncryptionAlgorithm.AES_256)31 .Build();3233 // Create a new operation instance34 ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.CreateNew(protectPDFOptions);3536 // Set operation input from a source file.37 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"protectPDFInput.pdf");38 protectPDFOperation.SetInput(sourceFileRef);3940 // Execute the operation.41 FileRef result = protectPDFOperation.Execute(executionContext);4243 // Save the result to the specified location.44 result.SaveAs(Directory.GetCurrentDirectory() + "/output/protectPDFOutput.pdf");45 }46 catch (ServiceUsageException ex)47 {48 log.Error("Exception encountered while executing operation", ex);49 }50 // Catch more errors here . . .51 }5253 static void ConfigureLogging()54 {55 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());56 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));57 }58 }59 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/protectpdf/protect-pdf.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 // Build ProtectPDF options by setting a User Password and Encryption19 // Algorithm (used for encrypting the PDF file).20 const protectPDF = PDFServicesSdk.ProtectPDF,21 options = new protectPDF.options.PasswordProtectOptions.Builder()22 .setUserPassword("encryptPassword")23 .setEncryptionAlgorithm(PDFServicesSdk.ProtectPDF.options.EncryptionAlgorithm.AES_256)24 .build();2526 // Create a new operation instance.27 const protectPDFOperation = protectPDF.Operation.createNew(options);2829 // Set operation input from a source file.30 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/protectPDFInput.pdf');31 protectPDFOperation.setInput(input);3233 // Execute the operation and Save the result to the specified location.34 protectPDFOperation.execute(executionContext)35 .then(result => result.saveAsFile('output/protectPDFOutput.pdf'))36 .catch(err => {37 if(err instanceof PDFServicesSdk.Error.ServiceApiError38 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {39 console.log('Exception encountered while executing operation', err);40 } else {41 console.log('Exception encountered while executing operation', err);42 }43 });44 } catch (err) {45 console.log('Exception encountered while executing operation', err);46 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Protect-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/protectpdf' \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 "passwordProtection": {10 "userPassword": "user_password"11 },12 "encryptionAlgorithm": "AES_128",13 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"14}'1516// Legacy API can be found here17// https://documentcloud.adobe.com/document-services/index.html#post-protectPDF
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 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.protectpdf.ProtectPDFWithOwnerPassword45 public class ProtectPDFWithOwnerPassword {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ProtectPDFWithOwnerPassword.class);910 public static void main(String[] args) {1112 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/protectPDFInput.pdf").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());232425 // Create new permissions instance and add the required permissions26 Permissions permissions = Permissions.createNew();27 permissions.addPermission(Permission.PRINT_LOW_QUALITY);28 permissions.addPermission(Permission.EDIT_DOCUMENT_ASSEMBLY);29 permissions.addPermission(Permission.COPY_CONTENT);3031 // Create parameters for the job32 ProtectPDFParams protectPDFParams = ProtectPDFParams.passwordProtectOptionsBuilder()33 .setOwnerPassword("password")34 .setPermissions(permissions)35 .setEncryptionAlgorithm(EncryptionAlgorithm.AES_256)36 .setContentEncryption(ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)37 .build();3839 // Creates a new job instance40 ProtectPDFJob protectPDFJob = new ProtectPDFJob(asset, protectPDFParams);4142 // Submit the job and gets the job result43 String location = pdfServices.submit(protectPDFJob);44 PDFServicesResponse<ProtectPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ProtectPDFResult.class);4546 // Get content from the resulting asset(s)47 Asset resultAsset = pdfServicesResponse.getResult().getAsset();48 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4950 // Creates an output stream and copy stream asset's content to it51 Files.createDirectories(Paths.get("output/"));52 OutputStream outputStream = Files.newOutputStream(new File("output/protectPDFWithOwnerPasswordOutput.pdf").toPath());53 LOGGER.info("Saving asset at output/protectPDFWithOwnerPasswordOutput.pdf");54 IOUtils.copy(streamAsset.getInputStream(), outputStream);55 outputStream.close();56 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {57 LOGGER.error("Exception encountered while executing operation", ex);58 }59 }60 }61
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ProtectPDFWithOwnerPassword/4// dotnet run ProtectPDFWithOwnerPassword.csproj56 namespace ProtectPDFWithOwnerPassword7 {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 new permissions instance and add the required permissions27 Permissions permissions = Permissions.CreateNew();28 permissions.AddPermission(Permission.PRINT_LOW_QUALITY);29 permissions.AddPermission(Permission.EDIT_DOCUMENT_ASSEMBLY);30 permissions.AddPermission(Permission.COPY_CONTENT);3132 // Build ProtectPDF options by setting an Owner/Permissions Password, Permissions,33 // Encryption Algorithm (used for encrypting the PDF file) and specifying the type of content to encrypt.34 ProtectPDFOptions protectPDFOptions = ProtectPDFOptions.PasswordProtectOptionsBuilder()35 .SetOwnerPassword("password")36 .SetPermissions(permissions)37 .SetEncryptionAlgorithm(EncryptionAlgorithm.AES_256)38 .SetContentEncryption(ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)39 .Build();4041 // Create a new operation instance42 ProtectPDFOperation protectPDFOperation = ProtectPDFOperation.CreateNew(protectPDFOptions);4344 // Set operation input from a source file.45 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"protectPDFInput.pdf");46 protectPDFOperation.SetInput(sourceFileRef);4748 // Execute the operation.49 FileRef result = protectPDFOperation.Execute(executionContext);5051 // Save the result to the specified location.52 result.SaveAs(Directory.GetCurrentDirectory() + "/output/protectPDFWithOwnerPasswordOutput.pdf");53 }54 catch (ServiceUsageException ex)55 {56 log.Error("Exception encountered while executing operation", ex);57 }58 // Catch more errors here . . .59 }6061 static void ConfigureLogging()62 {63 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());64 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));65 }66 }67 }68
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/protectpdf/protect-pdf-with-owner-password.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 new permissions instance and add the required permissions19 const protectPDF = PDFServicesSdk.ProtectPDF,20 protectPDFOptions = protectPDF.options,21 permissions = protectPDFOptions.Permissions.createNew();22 permissions.addPermission(protectPDFOptions.Permission.PRINT_LOW_QUALITY);23 permissions.addPermission(protectPDFOptions.Permission.EDIT_DOCUMENT_ASSEMBLY);24 permissions.addPermission(protectPDFOptions.Permission.COPY_CONTENT);2526 // Build ProtectPDF options by setting an Owner/Permissions Password, Permissions,27 // Encryption Algorithm (used for encrypting the PDF file) and specifying the type of content to encrypt.28 const options = new protectPDFOptions.PasswordProtectOptions.Builder()29 .setOwnerPassword("password")30 .setPermissions(permissions)31 .setEncryptionAlgorithm(protectPDFOptions.EncryptionAlgorithm.AES_256)32 .setContentEncryption(protectPDFOptions.ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)33 .build();3435 // Create a new operation instance.36 const protectPDFOperation = protectPDF.Operation.createNew(options);3738 // Set operation input from a source file.39 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/protectPDFInput.pdf');40 protectPDFOperation.setInput(input);4142 // Execute the operation and Save the result to the specified location.43 protectPDFOperation.execute(executionContext)44 .then(result => result.saveAsFile('output/protectPDFWithOwnerPasswordOutput.pdf'))45 .catch(err => {46 if(err instanceof PDFServicesSdk.Error.ServiceApiError47 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {48 console.log('Exception encountered while executing operation', err);49 } else {50 console.log('Exception encountered while executing operation', err);51 }52 });53 } catch (err) {54 console.log('Exception encountered while executing operation', err);55 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Protect-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/protectpdf' \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 "passwordProtection": {10 "ownerPassword": "owner_password"11 },12 "encryptionAlgorithm": "AES_256",13 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"14}'1516// Legacy API can be found here17// https://documentcloud.adobe.com/document-services/index.html#post-protectPDF