vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
719 stars 178 forks source link

signer.sign is not a function #69

Closed nilopaim closed 4 years ago

nilopaim commented 4 years ago

I'm trying to sign PDFfiles using NodeJs.

This is my code in a file called sign.js:

` var signer = require("node-signpdf"); var fs = require("fs");

function signIt() { const PATH_TO_PDF_FILE = "./declaracao.pdf"; const PATH_TO_P12_CERTIFICATE = "./Associacao.pfx";

var signedPdf = signer .sign( fs.readFileSync(PATH_TO_PDF_FILE), fs.readFileSync(PATH_TO_P12_CERTIFICATE) ) .then((result) => { console.log(result); }) .catch((err) => { console.log(err); });

console.log(signedPdf); }

signIt(); `

Anyway, when I try node sign.js I receive a signer.sig is not a function

What am I missing?

vbuch commented 4 years ago

Probably .default is what you are missing. See the dist code and you'll know how to access the module

nilopaim commented 4 years ago

Nice, @vbuch !

But the error changed to

SignPdfError: Could not find ByteRange placeholder: /ByteRange [0 /** /** /**]

Some another hint?

vbuch commented 4 years ago

Does declaracao.pdf contain a ByteRange placeholder?

nilopaim commented 4 years ago

It's a simple file create using LibreOffice. Just text, no images...

vbuch commented 4 years ago

Read the docs.