Product: Node.JS SDK
Product Version: 9.4.0
I’m trying to convert an aes encrypted XOD file to PDF using the Node.JS SDK. I’m trying to use the initStdSecurityHandlerUString
function for this, but it doesn’t appear to be working - I suspect this function is only intended for “standard” pdf encryption, not the xod encryption. How can I accomplish this?
Code
"use strict";
const {
PDFNet
} = require("@pdftron/pdfnet-node");
const LICENSE_KEY = "";
PDFNet.runWithCleanup(async () => {
let in_file = "encrypted-foobar12.xod"; // https://pdftron.s3.amazonaws.com/downloads/pl/encrypted-foobar12.xod
let out_file = "decrypted-foobar12.pdf";
try {
const pdfdoc = await PDFNet.PDFDoc.create();
await pdfdoc.initStdSecurityHandlerUString("foobar12");
await PDFNet.Convert.toPdf(pdfdoc, in_file);
await pdfdoc.save(out_file, PDFNet.SDFDoc.SaveOptions.e_linearized);
console.log("Converted file: " + in_file + "\nto: " + out_file);
} catch (err) {
console.log("Unable to convert file " + in_file);
console.log(err);
}
}, LICENSE_KEY)
.catch(function(error) {
console.log("Error: " + JSON.stringify(error));
})
.then(function() {
return PDFNet.shutdown();
});
Output
Unable to convert file encrypted-foobar12.xod
{
message: 'Exception: \n' +
'\t Message: An error occurred while converting the file.\n' +
'Detailed error:\n' +
'\tException: \n' +
'\t Message: XML Parsing error\n' +
'\t Conditional expression: false\n' +
'\t Version : 9.4.0-29d3f4d\n' +
'\t Platform : Linux\n' +
'\t Architecture : AMD64\n' +
'\t Filename : XMLParser.cpp\n' +
'\t Function : Advance\n' +
'\t Linenumber : 141\n' +
'\n' +
'\t Conditional expression: false\n' +
'\t Version : 9.4.0-29d3f4d\n' +
'\t Platform : Linux\n' +
'\t Architecture : AMD64\n' +
'\t Filename : Convert.cpp\n' +
'\t Function : ToPdf\n' +
'\t Linenumber : 2033\n',
type: 'PDFWorkerError'
}