Reading Content From A PDF Document Encrypted, and encryption technology used not known

I have a lending system where users will be required to upload financial statement when applying for a loan. There are customers whose statements are sent by financial institution having password encryption know to them only. Now the goal here is to have a script php/nodejs that can decrypt or get pdf content from the encypted document and output a new pdf document or any readable format that is not encrypted for use by the lending institution.

I am not sure if PDFTron has the capability to decrypt a pdf document that requires user to input password to make it readable. I’ m using windows 10 platform, to achieve what i want, I have tried to implement code sample for nodejs/javascript provided in your document. Unfortunately, I’m getting undefined node pop up window with “Assertion Failed” Error. Please advice on the way forward. Any assistance will be appreciated.

Please Check My Code Below:-
const express = require(“express”);

//const bodyParser = require(“body-parser”);

const app = express();

const cors = require(‘cors’);

require(‘dotenv’).config();

const { PDFNet } = require(’@pdftron/pdfnet-node’);

const port = process.env.PORT || 5000;

const main = async () =>{

const doc = await PDFNet.PDFDoc.create();

const page = await doc.pageCreate();

doc.pagePushBack(page);

doc.save('blank.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);

}

const removeDocSec = async() =>{

let ret = 0;

let securedDoc = null;

try {

    securedDoc  = await PDFNet.PDFDoc.createFromURL('example.pdf');

    if (!(await securedDoc.initSecurityHandler())) {

      let success = false;

      console.log("The password has been set to : 'test'");

      const passwordsToTry = ['32909210', 'testy', 'test'];

      for (let count = 0; count < passwordsToTry.length; count++) {

        const candidate = passwordsToTry[count];

        console.log("Trying password candidate: '" + candidate + "'");

        if (await securedDoc.initStdSecurityHandlerUString(candidate)) {

          success = true;

          console.log('The password is correct');

          break;

        } else {

          console.log('The password is incorrect.');

        }

      }

      if (!success) {

        console.log('Document authentication error...');

        ret = 1;

        return ret;

      }

    }

    securedDoc.lock();

    console.log('PDF document initialized and locked');

    const hdlr = await securedDoc.getSecurityHandler();

    console.log('Document Open Password: ' + (await hdlr.isUserPasswordRequired()));

    console.log('Permissions Password: ' + (await hdlr.isMasterPasswordRequired()));

    console.log('Permissions: ');

    console.log("\tHas 'owner' permissions: " + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_owner)));

    console.log('\tOpen and decrypt the document: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_doc_open)));

    console.log('\tAllow content extraction: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_extract_content)));

    console.log('\tAllow full document editing: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_doc_modify)));

    console.log('\tAllow printing: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_print)));

    console.log('\tAllow high resolution printing: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_print_high)));

    console.log('\tAllow annotation editing: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_mod_annot)));

    console.log('\tAllow form fill: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_fill_forms)));

    console.log('\tAllow content extraction for accessibility: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_access_support)));

    console.log('\tAllow document assembly: ' + (await hdlr.getPermission(PDFNet.SecurityHandler.Permission.e_assemble_doc)));

    // remove all security on the document

    securedDoc.removeSecurity();

    const docbuf = await securedDoc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_linearized);

    saveBufferAsPDFDoc(docbuf, 'not_secured.pdf');

    console.log('done');

} catch ({err}) {

    console.log(err);

    ret = 1;

}

return ret;

}

LICENSE_KEY = process.env.PDFNet_LICENSE_KEY;

//—Creating blank pdf

PDFNet.runWithCleanup(main, LICENSE_KEY).catch((err)=>{

console.log(err);

}).then(()=> {

PDFNet.shutdown();

})

//------ remove security from a pdf document

PDFNet.runWithCleanup(removeDocSec, LICENSE_KEY).catch((err)=>{

console.log(err);

}).then(()=> {

PDFNet.shutdown();

})

////-------End of remove security from a pdf document

Here Is the Sceenshot of Error I’m getting on trying nodejs script

Hello,

Yes, PDFTron provides the capability to decrypt a PDF file, using a password provided via the API.

The following guides and samples should be helpful:

To diagnose the crash, we would require a sample input file (with sample password) that could demonstrate the issue.

Does this file also crash the decryption example?