Cannot set property 'Annots' of undefined
See original GitHub issue`const signer = require(‘node-signpdf’).default; const fs = require(‘fs’); const { addSignaturePlaceholder } = require(‘./node-signpdf-master/dist/helpers’); const PDFDocument = require(‘pdfkit’);
const createPdf = (params = { placeholder: { reason : ‘Digital signed by my key’ }, text: ‘this is content pdf’, }) => new Promise((resolve) => { const pdf = new PDFDocument({ autoFirstPage: true, size: ‘A4’, layout: ‘portrait’, bufferPages: true, }); pdf.info.CreationDate = ‘’; pdf.fillColor(‘#333’).fontSize(25).moveDown().text(params.text);
const pdfChunks = []; pdf.on(‘data’, (data) => { pdfChunks.push(data); }); pdf.on(‘end’, () => { resolve(Buffer.concat(pdfChunks)); });
const refs = addSignaturePlaceholder({ pdf, reason: ‘I am the author’, …params.placeholder, });
Object.keys(refs).forEach(key => refs[key].end()); pdf.end();
});
const action = async () => { let pdfBuffer = await createPdf(); let p12Buffer = fs.readFileSync(__dirname + ‘/baominh.key.p12’)
let pdf = signer.sign(pdfBuffer, p12Buffer, { passphrase : ‘12345678’, asn1StrictParsing : true }); fs.writeFileSync(__dirname + ‘/demo.pdf’, pdf); }
action();` Hello! I have been the error: ‘Cannot set property ‘Annots’ of undefined’ when i runed the code above. Can you help me with this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Here is what I did to make it work with 0.9.0: https://github.com/vbuch/node-signpdf/commit/3755311b32592a165c0a9c3ed7c7cfeac76e8ff4
Some kind of fix will surely be needed for this and it should go with a next release.
Separate note: Another thing that needs to happen in that release is fix babel ->… braces vulnerabilities reported by npm and/or yarn. And… while looking at the npm audit I saw that
pdfkit
also has a vulnerable dep that will need to get upgraded. So… we have some time until the pdfkit team resolves their vulnerability. Once they do, we’ll also need to have a ready fix for the 0.9 issue we’re discussing here.Another separate note: There should be a nicer way to add annotations in a page. I’m basing this assumption on this code: https://github.com/foliojs/pdfkit/blob/5d527a32c87955f636b4220ad983dec208b4ffeb/lib/mixins/annotations.js So hopefully this can be improved as well for the next release. Should be something like pdfDocument.annotate({…annotation configuration})
This has rolled out into 1.0.0