gopdfannotationsdigital-signaturepades

PDF Signature Appearance is not Visible


I'm implementing visible digital signatures in PDF documents using incremental updates. I'm generating the signature using a PKCS#7 detached signature and adding a widget annotation to represent the visual signature. The signature validation works correctly, but the annotation (currently a simple colored rectangle for testing purposes) is not displayed in any PDF viewer.

Example document

The incremental update looks as following:


6 0 obj
<<
 /Type /Sig
 /Filter /Adobe.PPKLite
 /SubFilter /adbe.pkcs7.detached
 /Prop_Build <<
   /App << /Name /Digitorus#20PDFSign >>
 >>
 /ByteRange [0 938 3808 918]                    /Contents<308...000>
   /TransformMethod /FieldMDP
   /TransformParams <<
     /Type /TransformParams
     /Action /All
     /V /1.2
   /DigestMethod /SHA512
 >>
 /Name (John Doe)
 /Location (Somewhere)
 /Reason (Test with visible signature)
 /ContactInfo (None)
>>
endobj

7 0 obj
<<
  /Type /XObject
  /Subtype /Form
  /BBox [0 0 190 190]
  /Matrix [1 0 0 1 0 0]
  /Resources <<
  >>
  /FormType 1
  /Length 35
>>
stream
q
255 112 52 rg
0 0 190 190 re
f
Q
endstream
endobj

8 0 obj
<<
  /Type /Annot
  /Subtype /Widget
  /Rect [10 10 200 200]
  /AP << /N 7 0 R >>
  /Border [1 1 1]
  /P 3 0 R
  /F 132
  /FT /Sig
  /T (Signature 1)
  /V 6 0 R
>>
endobj

9 0 obj
<<
  /Type /Catalog
  /Pages 2 0 R
  /AcroForm <<
    /Fields [8 0 R]
    /SigFlags 3
  >>
>>
endobj

xref
6 4
0000000740 00000 n
0000004062 00000 n
0000004264 00000 n
0000004444 00000 n
trailer
    <<  /Root 9 0 R
    /Prev 565
    /Size 10
    >>
startxref
4554
%%EOF

Solution

  • It is not normal for signature placeholder to show colours in viewers.

    Bear with me while I show the methods most files follow, initially with your code first without signed.

    I have emulated your setting in an editor and show that, the same file in Acrobat reader (when unsigned), has no fill colour.

    NOTE the colours are set to the one you nominated as RGB background fill (Integer 252 112 52. However, as mentioned by "@Simon Pauget" those are not valid internally in a PDF as it uses floats 0-1). Hence in the following you will see them as /MK<</BG[1 .439 .204] and stream 1 .439 .204 rg but will be ignored by readers anyway.

    Condensed version just for testing method/behaviours.

    %PDF-1.1
    %¥±ë
    1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
    2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1/MediaBox[0 0 595 842]>>endobj
    3 0 obj<</Type/Page/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Times-Roman>>>>>>/Contents 4 0 R>>endobj
    4 0 obj<</Length 39>>
    stream
    BT /F1 18 Tf 0 0 Td (Hello World) Tj ET
    endstream
    endobj
    
    xref
    0 5
    0000000000 65535 f 
    0000000017 00000 n 
    0000000060 00000 n 
    0000000131 00000 n 
    0000000262 00000 n 
    trailer
    <</Root 1 0 R/Size 5>>
    startxref
    349
    %%EOF
    5 0 obj<</Type/Pages/Kids[6 0 R]/Count 1/MediaBox[0 0 595 842]>>endobj
    6 0 obj<</Type/Page/Parent 5 0 R/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Times-Roman>>>>>>/Contents 4 0 R/Annots[8 0 R]>>endobj
    7 0 obj<</Type/XObject/Subtype/Form/BBox[0 0 190 190]/Length 31/Resources<<>>>>
    stream
    1 .439 .204 rg 0 0 190 190 re f
    endstream
    endobj
    8 0 obj<</Type/Annot/Subtype/Widget/Rect[10 10 200 200]/AP<</N 7 0 R>>/P 6 0 R/F 4/FT/Sig/T(Signature1)/DA(0 0 0 rg /Times-Roman 0 Tf)/MK<</BG[1 .439 .204]>>>>endobj
    9 0 obj<</Type/Catalog/AcroForm<</DR<</Font<</Times-Roman 11 0 R>>>>/Fields[8 0 R]/SigFlags 3>>/Pages 5 0 R>>endobj
    
    xref
    5 5
    0000000509 00000 n 
    0000000580 00000 n 
    0000000725 00000 n 
    0000000861 00000 n 
    0000001027 00000 n 
    
    trailer
    <</Size 10/Root 9 0 R/Prev 349>>
    startxref
    1144
    %%EOF
    

    enter image description here

    Moving on to signed, (invisible and visible). If there are no contents the signed file placeholder will be set to invisible as the Marker and background are not required and would possibly interfere with a visible signature. A PDF syntax cleaner (would if unsigned) simply delete the colouration to match most viewers expectations.

    enter image description here

    Thus PDF editors and viewers alike will show "non graphic signature" as basically "invisible".

    enter image description here

    Part Answer Would be another increment along the lines of

    4554
    %%EOF
    3 0 obj<</Type/Page/Annots [8 0 R]/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Times-Roman>>>>>>/Contents 4 0 R>>endobj
    7 0 obj<</Type/XObject/Subtype/Form/BBox [0 0 190 190]/Matrix [1 0 0 1 0 0]/Resources<<>>/FormType 1/Length 35>>
    stream
    q 1 .439 .204 rg 0 0 190 190 re f Q
    endstream
    endobj
    xref
    3 1
    0000004726 00000 n
    7 1
    0000004872 00000 n
    trailer
    <</Root 9 0 R/Prev 4554/Size 10>>
    startxref
    5045
    %%EOF
    

    However older Acrobat Readers shows the new content but Adobe viewers say there is no new content seen here as "Document modified No" since the number of entries is the same. But either the dates or cerificates are still not to be trusted. A newer "Adobe Reader" may say different. enter image description here

    Readers that dont show signing will see the correct orange box and some readers will accept the file as "Signed with Changes"

    enter image description here