ProtectPDFOperation

ProtectPDFOperation

An operation that converts a PDF file into a password protected PDF file. The password is used for encrypting PDF contents and will be required for viewing the PDF file.

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 user password supports ASCII characters only; allowed minimum length of password is 6 characters and maximum length of password is 32 characters. For AES-256 encryption the user password supports Unicode character set and the maximum length of password is 127 UTF-8 bytes.

Sample Usage:


 const credentials = PDFToolsSdk.Credentials.serviceAccountCredentialsBuilder()
           .fromFile("pdftools-api-credentials.json")
           .build(),
       executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
       ProtectPDF = PDFToolsSdk.ProtectPDF,
       options = new ProtectPDF.options.PasswordProtectOptions.Builder()
           .setUserPassword("mypassword")
           .setEncryptionAlgorithm(PDFToolsSdk.ProtectPDF.options.EncryptionAlgorithm.AES_128)
           .build();
       protectPDFOperation = ProtectPDF.Operation.createNew(options),
       input = PDFToolsSdk.FileRef.createFromLocalFile('test/resources/protectPDFInput.pdf', ProtectPDF.SupportedSourceFormat.pdf);

 protectPDFOperation.setInput(input);

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

Members

(static, constant) SupportedSourceFormat

Properties:
Name Type Description
pdf string

Represents "application/pdf" media type

Supported source file formats for ProtectPDFOperation.

Methods

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

Constructs a ProtectPDFOperation instance with intended permission options. See PasswordProtectOptions for how to specify these permission options.

Parameters:
Name Type Description
options PasswordProtectOptions

for setting User Password and Encryption Algorithm (used for securing PDF).

Returns:

A new ProtectPDFOperation instance.

Type
ProtectPDFOperation

setInput(sourceFileRefnon-null)

Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

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

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>