vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
688 stars 175 forks source link

How can I import the plainAddPlaceholder helper in my project after I installed your package? #126

Closed megalypse closed 3 years ago

megalypse commented 3 years ago

Describe the bug and the expected behaviour I'm using this package on a typescript project, and I'm trying to sign an already existing PDF.

Is it a bug in signing or in the helpers? I would like to know how I can import the plainAddPlaceholder() helper and use it in my project.

I can't find it anywhere in the 'node-signpdf' import I did.

vbuch commented 3 years ago

Check the files in the dist folder: https://github.com/vbuch/node-signpdf/tree/develop/dist The helpers are not exported from the root. You may need to add add 'dist' to the import path. something like 'node-sginpdf/dist/helpers/plainAddPlaceholder'

megalypse commented 3 years ago
  const pdfBuffer = await pdf.create(document, options);
  const keyBuffer = fs.readFileSync('src/certs/certificate.p12');
  const preReadyPdf = plainAddPlaceHolder({
    pdfBuffer,
    reason: 'Test',
    signatureLength: keyBuffer.length
  })

  const signedPdf = signer.sign(pdfBuffer, keyBuffer)

I managed to import the helper just as you said, but even using it I still get this error message:

Error: No ByteRangeStrings found within PDF buffer at findByteRange (D:\Projetos\Typescript\PdfGeneratorV2\node_modules\node-signpdf\dist\helpers\findByteRange.js:28:11) at SignPdf.sign (D:\Projetos\Typescript\PdfGeneratorV2\node_modules\node-signpdf\dist\signpdf.js:50:36) at generateNotificationPdf (D:\Projetos\Typescript\PdfGeneratorV2\src\index.ts:38:43)

vbuch commented 3 years ago

You're signing pdfBuffer while you've added the placeholder to preReadyPdf hence No ByteRangeStrings found within PDF buffer

megalypse commented 3 years ago

Thanks