I'm trying to create a visible PDF signature pragmatically. Non-visible signature works but when I add the AP (appearance) object I get an error in Acrobat Reader saying the following: 'Object label badly formatted'.
The relevant XObject that I make look like this:
38 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[343.0 142.0 543.0 192.0]/FT/Sig/DR<<>>/T(signature38)/V 40 0 R/AP <</N 41 0 R>>>>
endobj
39 0 obj << /Length 52 /Type /XObject /Subtype /Form /Resources << /XObject << /n2 42 0 R /n0 43 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /BBox [0.0 0.0 200.0 50.0] /FormType 1 >> stream q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /n2 Do Q endstream endobj
40 0 obj
<</Contents <...>
/Type/Sig/SubFilter/adbe.pkcs7.detached/Location()/M(D:19700101010000+01'00')
/ByteRange [0000000000 0000064440 0000068536 0000220176]/Filter/Adobe.PPKLite/Reason()/ContactInfo()>>
endobj
41 0 obj << /Length 27 /Type /XObject /Subtype /Form /Resources << /XObject << /FRM 39 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /BBox [0.0 0.0 200.0 50.0] /FormType 1 >> stream q 1 0 0 1 0 0 cm /FRM Do Q endstream
endobj
42 0 obj << /Length 31 /Type /XObject /Subtype /Form /BBox [0.0 0.0 200.0 50.0] /Matrix [1.0 0.0 0.0 1.0 0.0 0.0] /Resources << /XObject << /img1 44 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /FormType 1 >>
stream q 200 0 0 50 0 0 cm /img1 Do Q
endstream
endobj
43 0 obj << /Length 0 /Type /XObject /Subtype /Form /BBox [0.0 0.0 200.0 50.0] /Resources << >> /FormType 1 >> stream endstream endobj
44 0 obj << /Length 218095 /Type /XObject /Subtype /Image /Filter /DCTDecode /BitsPerComponent 8 /Width 1300 /Height 1261 /ColorSpace /DeviceRGB
stream
-JPEG bytes-
endstream
I can't seem to find the error in this, but I must be missing something. I read this whole document by Adobe along with some other blogs and made my code according to that.
**UPDATE: **
I changed the code according to mkl's comment:
38 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[343.0 142.0 543.0 192.0]/FT/Sig/DR<<>>/T(signature38)/V 40 0 R/P 3 0 R/AP <</N 41 0 R>>>>
endobj
39 0 obj
<<
/Length 52
/Type /XObject
/Subtype /Form
/Resources <<
/XObject <<
/n2 42 0 R
/n0 43 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/BBox [0.0 0.0 200.0 50.0]
/FormType 1
>>
stream
q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /n2 Do Q
endstream
endobj
40 0 obj
<<content>>
endobj
41 0 obj
<<
/Length 27
/Type /XObject
/Subtype /Form
/Resources <<
/XObject <<
/FRM 39 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/BBox [0.0 0.0 200.0 50.0]
/FormType 1
>>
stream
q 1 0 0 1 0 0 cm /FRM Do Q
endstream
endobj
42 0 obj
<<
/Length 31
/Type /XObject
/Subtype /Form
/BBox [0.0 0.0 200.0 50.0]
/Matrix [1.0 0.0 0.0 1.0 0.0 0.0]
/Resources <<
/XObject <<
/img1 44 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/FormType 1
>>
stream
q 200 0 0 50 0 0 cm /img1 Do Q
endstream
endobj
43 0 obj
<<
/Length 0
/Type /XObject
/Subtype /Form
/BBox [0.0 0.0 200.0 50.0]
/Resources <<
>>
/FormType 1
>>
stream
endstream
endobj
44 0 obj << /Length 9451 /Type /XObject /Subtype /Image /Filter /DCTDecode /BitsPerComponent 8 /Width 1300 /Height 1261 /ColorSpace /DeviceRGB
stream
--JPEG bytes--
endstream
Here you can download my PDF.
UPDATE 2: It seems there was an error with my xref tables, where they weren't pointing to the right XObjects, that's why I was getting the error. However, now even though my PDF isn't corrupted and signature is ok (adobe will tell that the signature can't be verified because the certificate is self-signed but that's ok).
But now, I have another problem: The image doesn't appear. It's clickable and works but it's all blank.
A new version of the PDF is available here.