
How to Split PDF in Google Drive Folder with Google Apps Script and PDF.co
6 MIN READ
This tutorial shows you how to add or remove passwords and security restrictions from PDF files using asynchronous processing with the PDF.co Web API in JavaScript. Asynchronous processing allows tasks to run independently, so you can make your workflow more efficient by avoiding unnecessary waiting times.
Why Asynchronous Processing?
Asynchronous processing is crucial for handling tasks that take longer to complete, like processing large files, performing complex computations, or interacting with external APIs. Instead of pausing the entire program, it lets other tasks run simultaneously, enhancing performance and keeping your application responsive.
For more details on asynchronous processing, refer to the PDF.co Documentation.
The PDF.co Web API makes it easy to edit PDF documents across multiple programming languages, ensuring compatibility with various platforms and meeting your needs. The API allows you to modify PDFs by adding or removing passwords and security restrictions. Most importantly, it provides a secure system with encrypted connections for transmitting data files, ensuring your information stays protected. Additionally, the automated process saves you time and costs when editing documents.
Below are the details of the PDF Password and Security API, along with a demo that demonstrates these features using a simple example and sample code.
Here’s an easy-to-understand explanation of the parameters for the PDF Password and Security API. These parameters help you add or remove security features in PDF files:
url: A required string containing the URL to the source file. Supported URLs include publicly accessible links (e.g., Dropbox, Google Drive, or PDF.co’s built-in storage).ownerPassword: A required parameter for the primary password needed to add or remove security restrictions or encryption.userPassword: Optional password required to open the PDF. Use allowPrintDocument to control printing permission in supporting readers.encryptionAlgorithm: Specifies the encryption type for the process. Examples include RC4_40bit, RC4_128bit, and AES_128bit.allowAccessibilitySupport: Enables or restricts content extraction for accessibility (true or false).allowAssemblyDocument: Allows or prohibits assembling (reorganizing) the document (true or false).allowPrintDocument: Enables or disables printing the document (true or false).allowFillForms: Permits or blocks filling interactive forms, including signature fields (true or false).allowModifyDocument: Allows or restricts modifying the document (true or false).allowContentExtraction: Permits or prohibits copying content (true or false).allowModifyAnnotations: Enables or blocks interaction with text annotations and forms (true or false).printQuality: Defines the allowed printing quality, either HighResolution or LowResolution.encrypt: Enables (true) or disables (false) encryption for the output file stored in the cloud.name: Specifies a name for the output file.async: Set to true to start a background job. Retain the returned jobId. Check its status by sending POST https://api.pdf.co/v1/job/check with the JSON body {"jobid":"YOUR_JOB_ID"}. Include the same PDF.co API key in the x-api-key header and set Content-Type to application/json.expiration: (Optional) Sets how long the output file remains available before deletion.profiles: (Optional) Configures additional custom settings for the API operation.Here are sample source codes that demonstrate how to add or remove passwords from PDF documents using the PDF.co Password and Security API. These examples, written in JavaScript, show how to use key API parameters to perform these tasks. The implementation uses asynchronous processing with Axios, making the handling of requests and responses smooth and efficient.
To use this API, you need to provide the URL of the document you want to modify. Additionally, you must include your personalized API key, which is generated for you when you log in to the PDF.co platform.
Once you run the program, the API processes the document and provides a link to the modified PDF file. You can use this link to access the updated document and review the changes made to its password or security settings.
The following source code contains the program to add the password to an existing PDF document:
Code Sample: Here
The following step-by-step guide explains the source code to add the password to a document:
url, ownerPassword, userPassword, encryptionAlgorithm and output name in the request body. Preserve the exact property-name casing. The userPassword controls opening the PDF, while permission settings such as allowPrintDocument control corresponding actions in supporting PDF readers. Use a different owner password and keep it private, since opening with that password bypasses these restrictions.jobId to POST https://api.pdf.co/v1/job/check using the lowercase jobid property in the JSON body and the same API key. Wait briefly between checks while the status is working. Download the output only after success. Stop on failed, aborted or a job-not-found error, and set a polling deadline so the application does not wait indefinitely.Below is the screenshot of the edited document after adding the password using the PDF Password And Security API.
The following source code contains the program to remove the password from an existing PDF document:
Code Sample: Here
Below is the step-by-step guide for an explanation of the source code to remove the password from a document:
jobId to POST https://api.pdf.co/v1/job/check using the lowercase jobid property in the JSON body and the same API key. Wait briefly between checks while the status is working. Download the output only after success. Stop on failed, aborted or a job-not-found error, and set a polling deadline so the application does not wait indefinitely.Create an account, get an API key and test a request.