My journey through creating a PDF form (upgrading old Zend PDF library to be able to do it) continues.
I am struggling with checkbox and radio buttons, trying to get them displayed consistently. I did follow several guides and tips here and still there are differences in getting the button displayed in Chrome, Mozilla and Acrobat reader.
It seems no matter what I do, Acrobat reader ignores defines content stream and replaces it with it's own for checked and unchecked state of the button. Strangely enough, it displays the defined stream when the checked button has focus. So when I set in the stream I want the checkbox to display let's say a cross (either through ZaDb character or just simply two crossed lines), Acrobat reader only displays the cross when I click and check the button. As soon as I click elsewhere, the cross is replaced with the default check mark.
(Mozilla completely ignores any settings and just always displays their own icons so at least the user doesn't se two sets of icons.)
So is there any way how I can force Acrobat reader to show the set stream content? Or is there a way to set the stream content exactly the same as the default acrobat reader? I have no problem using the default check mark but I can't get the position right with possibly dynamic size of the checkbox.
Here is my source code with checkbox:
%PDF-1.5
%����
1 0 obj
<</Type /Catalog /Version /1.5 /Pages 2 0 R /Acroform <</NeedAppearances false /Fields [7 0 R ] >> /Names 10 0 R >>
endobj
2 0 obj
<</Type /Pages /Kids [13 0 R ] /Count 1 >>
endobj
3 0 obj
<</Type /Font /Subtype /Type1 /Encoding /WinAnsiEncoding /BaseFont /Helvetica >>
endobj
4 0 obj
<</Type /Font /Subtype /Type1 /Encoding /WinAnsiEncoding /BaseFont /ZapfDingbats >>
endobj
5 0 obj
<</Length 58 /Type /XObject /Subtype /Form /BBox [0 0 15 15 ] /Resources <</ProcSet [/PDF /Text /ImageC /ImageB /ImageI ] /Font <</ZaDb 4 0 R >> >>
/Matrix [1 0 0 1 0 0 ] >>
stream
/Tx BMC
q
BT
0 g /ZaDb 15 Tf
1 1 Td
(5) Tj
ET
Q
EMC
endstream
endobj
6 0 obj
<</Length 17 /Type /XObject /Subtype /Form /BBox [0 0 15 15 ] /Resources <</ProcSet [/PDF /Text /ImageC /ImageB /ImageI ] /Font <</ZaDb 4 0 R >> >>
/Matrix [1 0 0 1 0 0 ] >>
stream
Tx BMC
q
Q
EMC
endstream
endobj
7 0 obj
<</Type /Annot /Subtype /Widget /FT /Btn /Rect [200 350 215 365 ] /T (awesome) /DA (0 g /ZaDb 15 Tf) /F 4 /Ff 0 /V /Yes /AS /Yes
/DR <</Font <</ZaDb 4 0 R >> >> /AP <</N <</Yes 5 0 R /Off 6 0 R >> >> /P 13 0 R >>
endobj
8 0 obj
[]
endobj
9 0 obj
<</Names 8 0 R >>
endobj
10 0 obj
<</Dests 12 0 R >>
endobj
11 0 obj
[]
endobj
12 0 obj
<</Names 11 0 R >>
endobj
13 0 obj
<</Type /Page /LastModified (D:20240331174748+02'00') /Resources <</ProcSet [/Text /PDF /ImageC /ImageB /ImageI ] /Font <</F1 15 0 R /ZaDb 4 0 R >> >>
/MediaBox [0 0 595 842 ] /Contents [14 0 R ] /Annots [7 0 R ] /Parent 2 0 R >>
endobj
14 0 obj
<</Length 81 >>
stream
/F1 14 Tf
0 g
0 g
BT
40 350 Td
(Everything is awesome) Tj
ET
200 350 15 15 re
S
endstream
endobj
15 0 obj
<</Type /Font /Encoding /WinAnsiEncoding /Subtype /Type1 /BaseFont /Helvetica >>
endobj
xref
0 16
0000000000 65535 f
0000000015 00000 n
0000000147 00000 n
0000000206 00000 n
0000000303 00000 n
0000000403 00000 n
0000000670 00000 n
0000000896 00000 n
0000001126 00000 n
0000001145 00000 n
0000001179 00000 n
0000001215 00000 n
0000001235 00000 n
0000001271 00000 n
0000001519 00000 n
0000001651 00000 n
trailer
<</ID [<61666330663231353135323634656134> <37623763336532323165643662643432> ] /Size 16 /Root 1 0 R >>
startxref
1749
%%EOF
And here is the example PDF. https://filetransfer.io/data-package/eMwB3qGa#link
Of course I have tried setting on and off the Needppeareance and followed several other guidelines about similar topics here.
In Acrobat you have this option selected:
This causes Acrobat to recreate the appearance for the form fields and ignore your appearance. Because your field does not specify in its definition what symbol to use for the check symbol, Acrobat uses its default one.
Add the <</MK (5)>>
entry to your field widget dictionary and Acrobat will display your checkmark.
<<
/Type /Annot
/Subtype /Widget
/FT /Btn
/Rect [200 350 215 365 ]
/T (awesome)
/DA (0 g /ZaDb 15 Tf)
/F 4
/Ff 0
/V /Yes
/AS /Yes
/DR <</Font <</ZaDb 8 0 R>> >>
/AP <</N <</Yes 11 0 R/Off 10 0 R>> >>
/P 5 0 R
/MK <</CA (5)>>
>>