Unlock PDF via JavaScript

Decrypt (remove encryption) PDF Files programmatically using Aspose.PDF for JavaScript via C++

Unlock PDF Document Using JavaScript

Unlock PDF using the Aspose.PDF for JavaScript. Decrypting PDF files allows to access and view 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, to print a document, also you have to unlock PDF. If a PDF contains tables, images, or text that must be extracted for use in other documents or applications, decrypting files is essential. Unlock PDF and save time. For example, if you often enter a certain document and enter a complex password takes you a lot of time. Decrypting PDF 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 PDF may have encryption that causes compatibility or software issues. With the feature Unlock PDF Files 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 if you want to share it with others. In order to decrypt PDF file, we’ll use Aspose.PDF for JavaScript via C++ is a easy and secure toolkit used to work with PDF directly in the web browser. To install and use Aspose.PDF for JavaScript via C++ extract files from the ZIP archive.

How to Unlock PDF via JavaScript


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

  1. Open a PDF document using Document object.
  2. Create a password for user and owner.
  3. Call Document.Decrypt Method.
  4. Save the PDF file.

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

Password:

Output format:

Output file:

var ffileDecrypt = function (e) {
    const file_reader = new FileReader();
    file_reader.onload = (event) => {
    /*decrypt a PDF-file with password is "owner" and save the "ResultDecrypt.pdf"*/
    const json = AsposePdfDecrypt(event.target.result, e.target.files[0].name, "owner", "ResultDecrypt.pdf");
    if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
    else document.getElementById('output').textContent = json.errorText;
    /*make a link to download the result file*/
    DownloadFile(json.fileNameResult, "application/pdf");
    };
    file_reader.readAsArrayBuffer(e.target.files[0]);
};