Hi,
First of all, reattaching the PDF, now as a link to where I originally found
it:
https://help.queens.edu/hc/en-us/article_attachments/211567983/Signature_Test_Form.pdf
<https://help.queens.edu/hc/en-us/article_attachments/211567983/Signature_Test_Form.pdf>
If you will try signing the attached PDF twice with podofosign app, you should
get the same result (first signature violation)
podofosign -in unsigned.pdf -cert cert.pem -pkey key.pem -out signed.pdf
-password test \
-field-name Sign -field-use-existing -annot-units inch -annot-position
1,3,3,2,0.3 \
-annot-image 0,0,2,0.3,signature.png
podofosign -in signed.pdf -cert cert.pem -pkey key.pem -out signed_twice.pdf
-password test \
-field-name Sign2 -annot-units inch -annot-position 1,2,2,1,0.3 \
-annot-image 0,0,2,0.3,signature.png
About the code - it’s in Python with custom swig-based wrapper (no the pypodofo
one).
The working version roughly looks like this, should still be readable as
function names are all same with some syntactic sugar added:
doc = podofo.PdfMemDocument()
doc.LoadFromBuffer(input_data, False)
buffer = podofo.PdfRefCountedBuffer()
output_device = podofo.PdfOutputDevice(buffer)
if podofo.PdfParser(podofo.PdfVecObjects(), input_data, False).HasXRefStream():
doc.SetWriteMode(podofo.ePdfWriteMode_Clean)
doc.Write(output_device)
doc = podofo.PdfMemDocument()
doc.LoadFromBuffer(buffer.GetBuffer(), True)
else:
doc.LoadFromBuffer(input_data, True)
…
signature_field.SetSignature(signer.GetSignatureBeacon())
doc.WriteUpdate(signer, True)
signer.AdjustByteRange()
signer.Seek(0)
self._sign(signer=signer, cert=cert_data, pkey=pkey_data)
signer.Flush()
One more observation. In XRefStream case in addition to the signature itself,
WriteUpdate adds fonts, font boxes, all annotations (including those not
related to signatures), and it seems that it even adds new page tree.
I was unable to test on linearized PDFs unfortunately, as the version of PoDoFo
I have (the one from Mac homebrew) refuses to recognize them as linearized no
matter what.
> On 4 Nov 2020, at 09:11, zyx <[email protected]> wrote:
>
> On Tue, 2020-11-03 at 17:13 +0100, Peter Bel wrote:
>> I had the same issue, and I think I’ve found why the first signature
>> gets invalidated.
>
> Hi,
> thanks for looking on this. I've been wondering why it is so, but I've
> never got to the point of checking where the actual problem is. I
> thought the problem is that some object is overwritten, which shouldn't
> be (I thought about the Info), but I won't expect it being the XRef
> table, because that one is supposed to be updated, due to added
> objects.
>
>> Not sure if it’s parser or writer, it might be that parser finds the
>> first XRefStream and sets the HasXRefStream flag, ignoring the non-
>> stream XRef written by the update.
>
> Two questions: a) did you do it manually, or you've some sort of a
> "shareable" code, please? b) Does it apply only to this sort of the
> document, with an XRefStream, the other documents will still misbehave?
>
> Thanks and bye,
> zyx
>
>
>
> _______________________________________________
> Podofo-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/podofo-users
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users