pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: External signature in 2 steps
Date Wed, 26 Oct 2016 20:43:53 GMT
Am 26.10.2016 um 21:53 schrieb Fabricio Pombo Koch:
> Hi,
> I'm trying to sign a PDF with an external service. This service receives the PDF's content
(hash) and returns the signature (hash).
> I followed the "CreateSignature" and "CreateVisibleSignature" examples and I was able
to make it works.
> But, I need to sign the PDF in 2 steps:    1- Get PDF's content, calculate the hash and
send the hash to the service that is responsible to sign the hash.
>      2- Get the signature hash returned from the service and insert it into my PDF.
>
> Note that in the 2nd step I'm not in the same context from 1st step, so, I can't access
the PDF that was loaded in step 1. I would need to load it again.

You would have to use the new "external" strategy that exists since 
2.0.3, but without writing the signature. Before closing, get the 
ByteRange from the signature object.

HOWEVER... that one isn't available, because after being calculated the 
ByteRange isn't assigned back to the PDFBox structure.

(Open a signed PDF with NOTEPAD++ and search for ByteRange to understand 
what II mean)

So you'd have to reload the PDF; get the field (you know its name), and 
then the signature, then the ByteRange ( signature.getByteRange()  ). 
Close again.

Then write the signature that you got at the appropriate place in the 
file. This can be done without PDFBox.

I could do a change that you can access the byte range, i.e. don't have 
to reload the PDF just to get the byte range. However this will have to 
wait until mid next week, because I wouldn't have the time to become 
active if it doens't work. (Although I just tested it).

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message