Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.76k stars 647 forks source link

Add ByteRange to an existing placeholder #824

Closed vicpara closed 2 years ago

vicpara commented 3 years ago

In the assets folder of this repo there is with_signature. A document with pdf-lib that contains a /Sig placeholder without the V value it appears as empty and ready to be signed. Adobe Acrobat Reader can later on add a signature in the placeholder and it works.

How can I add a ByteRange to the Signature field so that I can then use node-signpdf to sign the document?

Appreciate any guidance in this direction.

I noticed that when Adobe DC signs the document, it adds another Widget to the same object id after the trailer. example before the trailer as in the unsigned pdf:

47 0 obj
<<
/Type /Annot
/Subtype /Widget
/FT /Sig
/Rect [ 211.35240347725002 292.9519915139995 461.35240347725005 222.95199151399947 ]
/T ([Signature1])
/F 4
/P 25 0 R
>>
endobj

after the trailer in the signed document:

47 0 obj
<<
/AP<</N 56 0 R>>
/F 132/FT/Sig/P 25 0 R/Rect[211.3524034772 292.951991514 461.3524034772 222.951991514]
/Subtype/Widget
/T([Signature2])
/Type/Annot
/V 55 0 R>>
endobj

...

55 0 obj
<</ByteRange[ 0 79276 83828 2443]                                          
/Contents<....>
/Filter/Adobe.PPKLite/M(D:20210312180058+02'00')
/Name(member: 77F0B2A8-82DA-4216-9680-858B5027D10E)
/Prop_Build<</App<</Name/Acrobat#20Reader/OS[/Mac]
/R 1376512/REx(2021.001.20142)
/TrustedMode true>>
/Filter<</Date(Feb 28 2021 20:08:37)
/Name/Adobe.PPKLite
/R 131104
/V 2>>
/PubSec<</Date(Feb 28 2021 20:08:37)/NonEFontNoWarn true
/R 131105>>>>
/SubFilter/adbe.pkcs7.detached
/Type/Sig>>
endobj
Hopding commented 2 years ago

Please open a Discussion if you're still having trouble with this.