latex3 / hyperref

Hypertext support for LaTeX
168 stars 37 forks source link

generated checkboxes are invalid (removed when roundtripping through pdf2ps -> ps2pdf; fail to display in a number of PDF viewers) #153

Open JasonGross opened 4 years ago

JasonGross commented 4 years ago

I have

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\fbox{\CheckBox[name=foo,checked=true]{}}
\end{Form}
\end{document}

This checkbox shows up fine in Adobe Reader, but the checkbox is unchecked in Chrome's PDF viewer, and does not show up at all in Firefox's PDF viewer nor in SumatraPDF. Worse, if I run pdf2ps foo.pdf foo.ps and then run ps2pdf foo.ps foo-ps.pdf, the resulting PDF file does not contain a checkbox. Note that pdf2ps warns with

   **** Error: Required entry /BBox not present in Form.
               Output may be incorrect.
               Output may be incorrect.
   **** Error: Stream object is missing the stream data.

Note also that when I open the original PDF in Adobe Reader, when I go to close it, Adobe Reader asks me if I want to save changes, suggesting that it's corrected some invalidity in the pdf behind the scenes. Indeed, if I do this, the resulting PDF displays checkboxes correctly in all PDF viewers, and displays the checkbox when I round-trip through a .ps file.

Here are all the generated files: Assuming I named the above foo.tex, then:

  1. pdflatex foo.tex gives foo.log and foo.pdf
  2. Opening foo.pdf:
    • in Chrome gives: image
    • in Firefox gives: image
    • in SumatraPDF gives: image
    • in Adobe Reader gives: image
  3. Running pdf2ps foo.pdf foo.ps; tar -czf foo.ps.tar.gz foo.ps; ps2pdf foo.ps foo-ps.pdf gives foo.ps.tar.gz and foo-ps.pdf and on the command line says

    
    $ pdf2ps foo.pdf foo.ps
    pdf2ps: security risk: running with elevated privileges
    The system cannot find the path specified.
    
    **** Error: Required entry /BBox not present in Form.
               Output may be incorrect.
               Output may be incorrect.
    **** Error: Stream object is missing the stream data.

4. Opening `foo-ps.pdf` in Adobe Reader shows: ![image](https://user-images.githubusercontent.com/396076/93006105-26fe8c00-f526-11ea-8712-14800cdef906.png)
5. Re-opening `foo.pdf` in Adobe Reader, and doing File -> Save As -> `foo2.pdf` gives: [foo2.pdf](https://github.com/latex3/hyperref/files/5213333/foo2.pdf)
6. Opening `foo2.pdf`:
  - in Chrome gives: ![image](https://user-images.githubusercontent.com/396076/93006117-5a411b00-f526-11ea-8e9f-639ec4179acd.png)
  - in Firefox gives: ![image](https://user-images.githubusercontent.com/396076/93006123-62995600-f526-11ea-9767-23fa5ff7de63.png)
  - in SumatraPDF gives: ![image](https://user-images.githubusercontent.com/396076/93006132-7c3a9d80-f526-11ea-8bab-5f350d102383.png)
7. Running `pdf2ps foo2.pdf foo2.ps; tar -czf foo2.ps.tar.gz foo2.ps; ps2pdf foo2.ps foo2-ps.pdf` gives [foo2.ps.tar.gz](https://github.com/latex3/hyperref/files/5213335/foo2.ps.tar.gz) and [foo2-ps.pdf](https://github.com/latex3/hyperref/files/5213336/foo2-ps.pdf)
8. Opening `foo2-ps.pdf`:
  - in Chrome gives: ![image](https://user-images.githubusercontent.com/396076/93006147-b73cd100-f526-11ea-9909-fc07e55894d6.png)
  - in Firefox gives: ![image](https://user-images.githubusercontent.com/396076/93006153-c58aed00-f526-11ea-9091-16556f080dd0.png)
  - in SumatraPDF gives: ![image](https://user-images.githubusercontent.com/396076/93006157-d20f4580-f526-11ea-92ce-b9716028062d.png)
  - in Adobe Reader gives: ![image](https://user-images.githubusercontent.com/396076/93006158-e05d6180-f526-11ea-9450-1b8870ad486a.png)

Perhaps related to #12?
u-fischer commented 4 years ago

You can avoid the question if the pdf should be saved by setting NeedAppearance=false in the form options. Beside this, yes the checkbox is faulty. But correcting it is not done by some simple change, and so has currently the status long term. Consider to use acrotex if you need working checkboxes directly.

JasonGross commented 4 years ago

I think you mean NeedAppearances=false, right? (I get an error on NeedAppearance.) But indeed this makes reader not ask about saving the file. Can you explain this? The manual mentions this option only in documenting the pdfa option, and does not say anything other than "Because of this, hyperref’s implementation of Forms looks ugly".

Consider to use acrotex if you need working checkboxes directly.

If I understand correctly, this amounts to using the eforms package, yes? I get exactly the same behavior with this file:

\documentclass{article}
\usepackage{hyperref}
\usepackage{eforms}
\begin{document}
\fbox{\checkBox[\V{Yes}]{foo}{\baselineskip}{\baselineskip}{Yes}}
\end{document}

so this problem seems to occur in acrotex as well as hyperref.

JasonGross commented 4 years ago

Additional interesting note: clicking on the checkbox in Chrome does not check it, but does change the border thickness: image

u-fischer commented 3 years ago

The implementation in hyperref will probably not change, but there is a new implementation of checkboxes in the pdfmanagement-testphase bundle. It uses correct appearances both for the Yes and the Off state. You could try if it works better. Documentation is in l3pdffield.pdf and l3pdffield-checkbox.pdf.

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress,pdfversion=2.0}
\documentclass[]{article}
\usepackage{hyperref}
\usepackage{l3pdffield-testphase}
\begin{document}
Test checkbox: 
\ExplSyntaxOn
\pdffield_checkbox:n{name=test,checked}
\ExplSyntaxOff
\end{document}