Closed sourav-prescriber-360 closed 5 years ago
Based off the error, It sounds like the document in question has been encrypted. There are a handful of "protection(s)" you can apply to the encrypted document, one being FillAndSign, if this is the case you will need to provide the password when you initial load the document in order to sign it. The snippet in your comment is utilizing the built in PoDoFo utility podofosign, which there is nothing wrong with, it's what NoPoDoFo::Signer is loosely based off of, but I am not certain how you would provide the password with this method. Below is the output from simply loading the document with NoPoDoFo and using the Encrypt object to lookup any protections that may be applied to the document. Looking at the last line you can see that this document does have protections applied, one of which is in fact the FillAndSign option.
> let mod = require('/home/developer/sources/github/corymickelson/npdf')
undefined
> let npdf = mod.nopodofo
undefined
> let doc = new npdf.Document()
Memory Document
undefined
> doc.load('/tmp/fda-356h_func_r13_secured_final.pdf', e => console.log(e))
undefined
> <</Type/XRef/DecodeParms<</Columns 5/Predictor 12>>/Encrypt 5352 0 R/Filter/FlateDecode/ID[<79F449E915A24CB0A18101EDC300D9CB><72DBDA3B5BB04A74A42C09DEDD9BB54F>]/Index[ 2232 1 2251 1 2255 3 2259 6 2270 2 2278 1 2284 1 2287 1 2452 1 2454 4 2460 2 2463 1 2470 1 2472 1 2484 1 5350 1 5352 1 5586 13 5609 1 5633 1 5635 1 5637 1 5639 2 5642 1 5644 2 5647 1 5654 1 5656 1 5658 1 5660 1 5662 1 5664 1 5747 111]/Info 5350 0 R/Length 190/Prev 116/Root 5353 0 R/Size 5858/W[ 1 3 1]>>
null
> doc.encrypt
Encrypt {}
> doc.encrypt.protections
{ Accessible: true,
Print: true,
Copy: true,
DocAssembly: false,
Edit: false,
EditNotes: true,
FillAndSign: true,
HighPrint: true }
>
If you have the password you can
doc.load('/path/to/doc.pdf', {password: 'password'}, err => {
if(err) {/*handle error*/}
// now you can check that you have the ability to sign
if (doc.encrypt.protections.FillAndSign) {
// sign your doc
}
But if I try with Adobe Acrobat, I can click the sign button and sign it using my certificate. It doesn't ask me to put any password. Does Adobe Acrobat authenticated to do it in someway ?
As of now PoDoFo 0.9.6 does not include support for encrypt/decrypt with a certificate, only with a password. This does seem like a critical feature to have though so I will reach out to the maintainers of PoDoFo to try and get some information on if this is something in their roadmap, and if not what type of effort it would be to incorporate this into their next release. Thank you for trying NoPoDoFo and submitting new issues.
Closing this issue as it need first be implemented in PoDoFo before NoPoDoFo
I was able to test the library using the docker image you suggested and its working flawlessly. I was trying to sign a specific pdf which I have to sign finally.
podofosign -in FDA-356h_func_R13_Secured_final.pdf -cert certificate.pem -out test.pdf -pkey key.pem
and got the error:
Error: An error 53 occurred during the sign of the pdf file: