ProtectPDFOperation

ProtectPDFOperation

An operation that is used for securing PDF document with password(s). The password(s) is used for encrypting the PDF document and setting the restriction on certain features like printing, editing and copying in the PDF document.

The supported algorithm for encrypting the PDF contents are listed here. The PasswordProtectOptions.EncryptionAlgorithm object can be used to set the encryption algorithm.

  • AES-128
  • AES-256
For AES-128 encryption the password supports LATIN-I characters only. For AES-256 encryption the password supports Unicode character set.

Sample Usage:


 const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
           .withClientId("PDF_SERVICES_CLIENT_ID")
           .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
           .build(),
       executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
       ProtectPDF = PDFServicesSdk.ProtectPDF,
       protectPDFOptions = ProtectPDF.options,
       permissions = protectPDFOptions.Permissions.createNew();

 permissions.addPermission(protectPDFOptions.Permission.PRINT_LOW_QUALITY);
 permissions.addPermission(protectPDFOptions.Permission.EDIT_DOCUMENT_ASSEMBLY);
 permissions.addPermission(protectPDFOptions.Permission.COPY_CONTENT);

 const options = new protectPDFOptions.PasswordProtectOptions.Builder()
 		.setUserPassword("openpassword")
 		.setOwnerPassword("permissionspassword")
 		.setPermissions(permissions)
 		.setEncryptionAlgorithm(protectPDFOptions.EncryptionAlgorithm.AES_256)
 		.setContentEncryption(protectPDFOptions.ContentEncryption.ALL_CONTENT_EXCEPT_METADATA)
 		.build(),
       protectPDFOperation = ProtectPDF.Operation.createNew(options),
       input = PDFServicesSdk.FileRef.createFromLocalFile('~/Documents/protectPDFInput.pdf', ProtectPDF.SupportedSourceFormat.pdf);

 protectPDFOperation.setInput(input);

 protectPDFOperation.execute(executionContext)
     .then(result => result.saveAsFile('protectPDFOutput.pdf'))
     .catch(err => console.log(err));

Members

(static, constant) SupportedSourceFormat

Description:
Properties:
Name Type Description
pdf string

Represents "application/pdf" media type

Supported source file formats for ProtectPDFOperation.

Methods

(static) createNew(optionsnon-null) → {ProtectPDFOperation}

Description:
Parameters:
Name Type Description
options PasswordProtectOptions

Options for securing PDF file with password(s).

Returns:

A new ProtectPDFOperation instance.

Type
ProtectPDFOperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

execute(contextnon-null) → {Promise.<FileRef>}

Description:
  • Executes this operation using the supplied context and returns a Promise which resolves to the operation result.

    The resulting file may be stored in the system temporary directory (per the os.tempdir(), symlinks are resolved to the actual path). See FileRef for how temporary resources are cleaned up.

Parameters:
Name Type Description
context ExecutionContext

The context in which the operation will be executed.

Throws:
  • if an API call results in an error response.

    Type
    ServiceApiError
  • if service usage limits have been reached or credentials quota has been exhausted.

    Type
    ServiceUsageError
Returns:

A promise which resolves to the operation result.

Type
Promise.<FileRef>