5

I am creating a series of laboratory exercises for my University. Thus, I created a .cls file that includes every package and applies any format I need. Among the included packages is the eforms package to create fillable fields and soul package to apply highlighting. Note that I use XeLaTeX for compiling. My main problem is that when I close the pdf, Adobe Reader always prompts "Do you want to save changes to ... before closing?" even no changes are made in those fields, even there is not any field at all. How can I overcome that issue while preserving the visibility of my fields?

A possible solution is to set true the pdfa option of hyperref package. That option disables a variety of properties that prevent the document from being PDF/A compliant. One of those properties is the NeedAppearances, which is set to false instead of default true. The result of that action is that fields are invisible unless they are clicked. The same behavior also is observed by fields created using hyperref commands.

Another possible solution is to use pdfx package with the a-3b option. This solution works almost like a charm, document claims compliance with PDF/A standard, all fields are visible and document is opened in read-only mode, so Adobe Reader doesn't ask for saving for no reason. Unfortunately, pdfx messes with soul package and the \hl{} command for highlighting; doesn't allow text to be highlighted. For example, when a whole sentence is highlighted with \hl, only whitespaces inside the sentence are displayed as highlighted. Thus, this solution cannot be applied since highlighting is a mandatory.

Foxit Reader, on the other hand, seems to be smarter. With the default setting (no pdfx and no pdfa option of hyperrref) Foxit knows when a field is edited and only then asks for saving. But, Foxit's performance is poor compared to Adobe Reader.

So, I am thinking a variety of solutions:

  • Is there any way to instruct Adobe Reader, possibly through latex commands, to open a document as read-only, in a similar way that Adobe Reader does when opens a PDF/A document?

  • Since PDF/A format doesn't seem a bad perspective, is there any way to support highlighting in PDF/A documents, with soul package or with an alternative method/package?

EDIT: I also tried to experiment with a simple example of eforms from here: http://www.math.uakron.edu/~dpstory/acrotex/examples/html/eforms_tst.pdf. The original pdf does not prompt for saving. Although, I compiled the source file that is attached using pdflatex and the prompt appeared again! I updated all packets from MikTeX console and the issue still persists.

2 Answers 2

3

A bit of JavaScript that is executed just before the document closes (/WC <<...>> % "will close") un-dirties the PDF:

\documentclass{article}

\usepackage{eforms}

\usepackage{pdfbase} %\pbs_pdfcatalog:n{...}
\ExplSyntaxOn
\AtEndDocument{
  \pbs_pdfcatalog:n{
    /AA <<    % additional document actions
      /WC <<  % "will close" trigger event
        /S/JavaScript /JS (this.dirty=false;)
      >>
    >>
  }
}
\ExplSyntaxOff

\begin{document}
    % Content containing form fields, such as...
    Don’t \pushButton[\CA{Push Me}]{myButton}{}{12bp},
    I fall down easily.
\end{document}
10
  • 2
    This solution doesn't seem to work. I used your code as it is in a new document, and XeLaTeX does not even recognize \pdfcataog. All other compilers (pdflatex, latex, lualatex) compile successfully, but at closing of the document, the same question is being asked. Aug 25, 2018 at 13:40
  • Sorry, but my example works for me. Not asking for saving. I updated it to be compilable with XeLaTeX.
    – AlexG
    Aug 26, 2018 at 12:57
  • Unfortunately, this solutions didn't work for me. It seems that it isn't a code issue. I added to my original post the description of a new unsuccessful attempt. Aug 28, 2018 at 15:58
  • Could you please provide a minimal compilable code example that demonstrates the issue?
    – AlexG
    Aug 28, 2018 at 17:06
  • 1
    That is a minimal compilable code. Just loading the eforms package, no fields at all. Adding your code, gives the same result; asks for saving the document. \documentclass{article} \usepackage{eforms} \begin{document} Only text. \end{document} Aug 28, 2018 at 17:33
0

Putting the this.dirty=false command in the \OpenAction JavaScript worked for me:

\documentclass{article}
\usepackage{eforms}
% you can of course have more than this in your OpenAction
\OpenAction{/S/JavaScript/JS(this.dirty=false;)}

\begin{document}
Only text. 
\end{document}

This solution also has the benefit of not always clearing the dirty bit. That is if you fill out the form, Acrobat will ask you to save it.

1
  • 1
    eforms must have changed in the meantime. Now it works again, after the edit
    – AlexG
    Aug 28, 2020 at 9:55

You must log in to answer this question.

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