Unlock PDF via JavaScript

Decrypt (remove encryption) PDF Files programmatically using Aspose.PDF for Node.js via C++ Library

Unlock PDF Document Using JavaScript

Unlock PDF using the Aspose.PDF for Node.js. Decrypting PDF files allows access and view of the content within the file. Also, you may need to access a password-protected PDF containing important information or documents. Sometimes, there is a need to change a PDF document, such as correcting errors or updating outdated information. Unlock PDF and get the ability to edit the content. By the way, you also have to unlock a PDF to print a document. Decrypting files is essential if a PDF contains tables, images, or text that must be extracted for use in other documents or applications. Unlock PDF and save time. For example, if you often enter a certain document and enter a complex password, it takes you a lot of time. Decrypting PDFs can be important when archiving or backing up important documents. It ensures that the archived copies are easily accessible and can be restored if needed. Some PDFs may have encryption that causes compatibility or software issues. With the Unlock PDF Files feature by Aspose.PDF, you can resolve these problems and allow for seamless access and use. If you have an encrypted PDF file and you no longer need a password to access its contents, decryption will make the file readable to all users. This can be useful if the document is open or you want to share it with others. In order to decrypt PDF files, we’ll use Aspose.PDF for Node.js via C++, which is an easy and secure toolkit used to work with PDF directly in the web browser. To install and use Aspose.PDF for Node.js via C++, extract files from the ZIP archive.

How to Unlock PDF via JavaScript

You need Aspose.PDF for Node.js via C++ to try the code in your environment.

  1. Import the Aspose.PDF for Node.js module.
  2. Define a constant for output file.
  3. Call the AsposePdf function.
  4. Call the AsposePdfDecrypt.
  5. Use the console.log method to print the result

The provided JavaScript code snippet shows how to unlock PDF documents using the Aspose.PDF library. It opens a PDF document named ‘Decrypt.pdf’ located in the directory specified by the variable ‘dataDir’. After opening, the code attempts to decrypt the opened PDF using the password ‘password’. As a result, the code saves the updated PDF document to a file named ‘Decrypt_out.pdf’ in the same directory specified by the ‘dataDir’ variable. This code snippet is a simplified example of how you might use a Aspose.PDF library or framework to unlock a password-protected PDF file and save the decrypted version. The following example demostrates how to unlock PDF document in JavaScript:

Unlock PDF Document - JavaScript

This sample code shows how to to decrypt PDF file - JavaScript

Input file:

File not added


Output format:

Output file:

const AsposePdf = require('../AsposePDFforNode.js');
const pdf_encrypt_file = './ResultEncrypt.pdf';
AsposePdf().then(AsposePdfModule => {
    /*Decrypt a PDF-file with password is "owner" and save the "ResultDecrypt.pdf"*/
    const json = AsposePdfModule.AsposePdfDecrypt(pdf_encrypt_file, "owner", "./ResultDecrypt.pdf");
    console.log("AsposePdfDecrypt => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);