Estou usando o exemplo do README.md desse GitHub para usar a biblioteca, mas está gerando esse erro:
[nodemon] starting `node -r esm index.js`
Server run in port 3001
(node:22076) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
at getXref (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/read-pdf.js:88:34)
at getFullXrefTable (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/read-pdf.js:67:25)
at readRefTable (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/read-pdf.js:49:25)
at Object.readPdf [as default] (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/read-pdf.js:23:20)
at new PdfCreator (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/pdf-creator.js:30:43)
at /Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/plain-add-placeholder.js:54:35
at step (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/plain-add-placeholder.js:33:23)
at Object.next (/Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/plain-add-placeholder.js:14:53)
at /Users/william/Sites/testes/pdf-node/node_modules/pdf-signer/dist/pdf/node-signpdf/plain-add-placeholder.js:8:71
at new Promise (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22076) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:22076) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
import express from 'express'
import { sign } from 'pdf-signer'
import fs from 'fs'
import dateFormat from 'dateformat'
const app = express()
const port = 3001
const gerapdf = async () => {
const p12Buffer = fs.readFileSync(`will.pfx`) // CPF/CNPJ A1 ICP-Brasil: Use original .pfx file
const pdfBuffer = fs.readFileSync(`output.pdf`)
const signature = 'Your Name'
const password = 'pdfsigner'
const signedPdf = await sign(pdfBuffer, p12Buffer, password, {
reason: 'Test',
email: '[email protected]',
location: 'City, BR',
signerName: signature,
annotationAppearanceOptions: {
signatureCoordinates: { left: 20, bottom: 120, right: 190, top: 20 },
signatureDetails: [
{
value: signature,
fontSize: 5,
transformOptions: { rotate: 0, space: 2, tilt: 0, xPos: 0, yPos: 32 },
},
{
value: 'Este arquivo foi assinado digitalmente',
fontSize: 5,
transformOptions: { rotate: 0, space: 2, tilt: 0, xPos: 0, yPos: 25.4 },
},
{
value: 'Assinado em ' + dateFormat(new Date(), 'd/mm/yyyy HH:MM:ss'),
fontSize: 5,
transformOptions: { rotate: 0, space: 2, tilt: 0, xPos: 0, yPos: 18 },
},
{
value: 'Verifique o arquivo em verificador.iti.gov.br',
fontSize: 5,
transformOptions: { rotate: 0, space: 2, tilt: 0, xPos: 0, yPos: 11 },
},
]
},
}).then(content => fs.writeFileSync('signed.pdf', content))
}
app.get('/', (req, res) => {
gerapdf()
res.send('Hello World')
})
app.listen(port, () => {
console.log(`Server run in port ${port}`)
})
Já tentei várias coisas para desfazer esse erro e não consegui.