nrhirani / node-qpdf

A Content Preserving transformations on PDFs wrapped around QPDF
MIT License
51 stars 54 forks source link

Example of the callback function for the third argument #9

Closed waynellin closed 5 years ago

waynellin commented 5 years ago

qpdf.encrypt(localFilePath, options, outputFilePath); and qpdf.decrypt(localFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF', outputFilePath); requires callback for outputFilePath. Where do we actually provide the string for output location? and what's an example for the callback function?

andreaswk commented 5 years ago

Here is a working example using the callback argument:



var options = {
  keyLength: 40,
  password: 'STRONG'
};
qpdf.encrypt('./sample.pdf', options, function(err, data) {
  if (err) {
    console.log(err);
  } else {
    const writeStream = fs.createWriteStream('./secured.pdf');
    data.pipe(writeStream);
  }
});