4

I'm using this simple example:

\documentclass[hidelinks, english, a4paper, 11pt]{scrartcl}

\usepackage{hyperref}   % typeset hyperlinks
\usepackage[ngerman]{babel}

\begin{document}
\begin{Form}
    \CheckBox[name=asd]{label}
\end{Form}
\end{document}

I understand it relies heavily on the PDF viewer, how those check boxes work, and how they appear.

I can't seem to get this checkbox working. When I view this in Evince, the box just doesn't do anything when clicked. In Chrome, it creates a red square, which I think means it's checked, but I'm unsure. PDF.js (the PDF viewer inside Firefox) does absolutely nothing.

I have yet to check with Adobe Acrobat Reader, but this is getting frustrating already.

What I'm eventually trying to do, is create a form as a PDF, that can be filled out, and then printed, it is not meant to be sent like an online form.

What I need, is the Box to be visible even when unchecked. The checked box should look like this: ⊠ (Unicode symbol U+22A0 "SQUARED TIMES") while the unchecked box should look like an empty box of the same kind.

Since it doesn't work in any of the viewers that are readily available to me, I'm a bit at a loss here. This form should work in as many viewers as possible. Things like \TextField{} works fine.

Please suggest me the best practice, if possible.

I use xelatex on Linux (TeX Live 2014/dev)

5
  • Currently the only free PDF viewer that supports such things is Acrobat Reader.
    – d-cmst
    Sep 9, 2014 at 11:20
  • @dcmst This is actually bad news for me and my boss. Does that mean, there is currently no "best practice" at all?
    – polemon
    Sep 9, 2014 at 11:34
  • I'm not sure what you mean, but checkboxes tend to be unpredictable even in different versions of acrobat reader or in the same version in different OSes, so I'd say there is nothing guaranteed to work across different viewers... Out of curiosity I tried your code in all the viewers I have installed on my (Linux) machine and it works fine only in acrobat reader 9. In some viewers (like muPDF) it shows nothing while in others it shows some very ugly artifacts (Okular, Evince, qpdfview).
    – d-cmst
    Sep 9, 2014 at 13:32
  • @dcmst Well, the interesting thing is, that textfields and pull-down menus work fine. Since PDF is supposed to be as portable as possible, this is kind of shocking.
    – polemon
    Sep 9, 2014 at 14:28
  • 3
    PDF used to stand for Proprietary Document Format until Apple made it a standard. ;-) Sep 9, 2014 at 17:45

1 Answer 1

3

I stumbled onto this problem today. For checkboxes, XeTeX 3.14159265-2.6-0.99992 (TeX Live 2015/Debian) produces PDF objects which do not include the so-called "appearance dictionary" (/AP). Clicking the checkbox may actually change its state, but it will not have visible effect. This might actually be a bug in xelatex and/or the hyperref package.

I tried fixing the PDF manually, but no mentally sane person should ever write PDF code by hand. I managed to find a workaround using python3-pdfrw 0.3. It copies the appearance dictionary from a working checkbox (generated by LibreOffice Writer) into the checkbox objects in the PDF produced by xetex:

#!/usr/bin/env python3

import sys
import os

from pdfrw import PdfReader, PdfWriter
from pdfrw.findobjs import find_objects
from pdfrw.objects import PdfName

for annot in find_objects(
  PdfReader("libreform.pdf").pages, 
  valid_types=(PdfName.XObject,PdfName.Annot,), 
  valid_subtypes=(PdfName.Widget,)
):
  if (annot.FT == '/Btn'):
    AP = annot.AP

outfn = sys.argv[2]
inpfn = sys.argv[1]
pdf = PdfReader(inpfn)
pages = pdf.pages
for annot in find_objects(
  pages, 
  valid_types=(PdfName.XObject, None), 
  valid_subtypes=(PdfName.Widget,)
):
  if (annot.FT == '/Btn'):
    annot.AP = AP
    annot.Type = "/Annot"

writer = PdfWriter(outfn, trailer=pdf)
writer.write()

The code and example files can be found at https://ssl.hehoe.de/zeug/pdflatexCheckboxFix .

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .