HTML JPG PDF XML DOCX
  Product Family
PDF

Decrypt PDF in Node.js SDK

API for decrypting PDF documents using Cloud Node.js SDK

Get Started

How to decrypt PDF via Node.js SDK

To decrypt PDF document, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.

Package Manager Console Command


     
    npm install asposepdfcloud --save
     
     

Steps to decrypt PDF via Cloud Node.js

Aspose.PDF Cloud developers can easily load & decrypt PDF in just a few lines of code.

  1. Read the local PDF file.
  2. Upload the PDF file to the Aspose.PDF Cloud storage.
  3. Decrypt it using the owner password.
  4. Download the result if needed it.
 

Decrypt PDF using Node.js


    import credentials from "../../../Credentials/credentials.json"  with { type: "json" };    // json-file in this format: { "id": "*****", "key": "*******" }
    import fs from 'node:fs/promises';
    import path from 'node:path';
    import { PdfApi } from "../../src/api/api.js";

    const configParams = {
        LOCAL_FOLDER: "C:\\Samples\\",
        PDF_DOCUMENT_NAME: "sample_encrypted.pdf",
        LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
        DOCUMENT_PASSWORD: "Owner-Password"
    };

    const pdfApi = new PdfApi(credentials.id, credentials.key);

    const pdfEncoder = {
        async uploadDocument () {
            const fileNamePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
            const pdfFileData = await fs.readFile(fileNamePath);
            await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData)
                .then(() => console.log("File: '" + configParams.PDF_DOCUMENT_NAME +"' successfully uploaded."));
        },

        async downloadResult() {
            const changedPdfData = await pdfApi.downloadFile(configParams.PDF_DOCUMENT_NAME);
            const filePath = path.join(configParams.LOCAL_FOLDER, configParams.LOCAL_RESULT_DOCUMENT_NAME);
            await fs.writeFile(filePath, changedPdfData.body);
            console.log("Downloaded: " + filePath);
        },

        async decrypt_document() {
            const password_encoded = btoa(configParams.DOCUMENT_PASSWORD)

            const response = await pdfApi.postDecryptDocumentInStorage(configParams.PDF_DOCUMENT_NAME, password_encoded);

            if (response.body.code == 200)
                console.log("decrypt_document(): Document #'" + configParams.PDF_DOCUMENT_NAME + "' successfully decrypted.")
            else
                throw new Error("decrypt_document(): Failed to decrypt document #'" + configParams.PDF_DOCUMENT_NAME + "'. Response code: {" + response.code + "}")
        },
        
    }

    async function main() {
        try {
            await pdfEncoder.uploadDocument();
            await pdfEncoder.decrypt_document();
            await pdfEncoder.downloadResult();
        } catch (error) {
            console.error("Error:", error.message);
        }
    }
 

Decrypt PDF

Decrypting a PDF document is crucial when access to its contents is restricted due to encryption. It allows authorized users to regain full control over the file, enabling editing, viewing, and content extraction. This process is especially important in workflows where secure documents must be accessed programmatically or integrated into larger systems.

Using tools like Aspose.PDF Cloud, decryption can be performed easily and securely with just the correct owner or user password. This ensures sensitive information remains protected while still allowing flexibility for those who need legitimate access.

Ultimately, decrypting a PDF enables smooth document handling and reinforces the importance of strong yet manageable document security practices. Decrypt PDF documents with Aspose.PDF Cloud Node.js SDK.

With our Node.js library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free Apps to test the functionality online.