1

I am trying to use node-qpdf

I just did simple:

Test.pdf is inside directory where index.js is

var qpdf = require('node-qpdf');

var options = {
    keyLength: 128,
    password: 'test123',
    restrictions: {
        print: 'low',
        useAes: 'y'
    }
}
var localFilePath ='Test.pdf';
var outputFilePath ='test';
qpdf.encrypt(localFilePath, options, outputFilePath);

I am getting error like:

Run: nodemon index.js

[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
C:\Users\Rad\Desktop\node-qpdf-master\test\node_modules\node-qpdf\index.js:56
        return callback(null, outputStream);
               ^

TypeError: callback is not a function
    at Object.Qpdf.encrypt (C:\Users\Rad\Desktop\node-qpdf-master\test\node_modules\node-qpdf\index.js:56:16)
    at Object.<anonymous> (C:\Users\Rad\Desktop\node-qpdf-master\test\index.js:13:6)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11
[nodemon] app crashed - waiting for file changes before starting...

1 Answer 1

7

I think they haven't updated the docs, I read their codes, you must put outputFile and change your options into like this.

 var options = {
    keyLength: 256,
    password: '12345',
    outputFile: '<your output name file>',
    restrictions: {
      modify: 'none',
      extract: 'n'
    }

  var doc = await qpdf.encrypt(`${fileLocation}.pdf`, options)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.