Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkbox does not display in acrobat reader #19

Open
fabboyrie opened this issue Oct 1, 2019 · 12 comments
Open

checkbox does not display in acrobat reader #19

fabboyrie opened this issue Oct 1, 2019 · 12 comments

Comments

@fabboyrie
Copy link

fabboyrie commented Oct 1, 2019

When I use fpdm, checkbox appears correctly in okular but not in latest acrobat reader.

With the following change in src/fpdm.php, it works but I do not know what I am really doing...

@ -966,7 +958,7 @@
                         }
                         $CurLine =$this->pdf_entries[$field_checkbox_line];
                         $OldLen=strlen($CurLine);
-                        $CurLine = '/AS /'.$state;
+                       $CurLine = '/AS /'.$state."\n/DV /$state\n/V /$state";
                         $NewLen=strlen($CurLine);
                         $Shift=$NewLen-$OldLen;
                         $this->shift=$this->shift+$Shift;

@JUVOJustin
Copy link

I can confirm this fixes the display error for acrobat. Thx @fabboyrie

@jjjrmy
Copy link

jjjrmy commented Oct 10, 2020

thanks!

@imclean557
Copy link

Can you submit a pull request?

@fabboyrie
Copy link
Author

Done
#42

It's my first pull request, I hope I made no mistakes.

@TristanHammat-AgilisIT
Copy link

TristanHammat-AgilisIT commented Dec 11, 2020

This doesn't update /V or /DV if present but rather it just adds new ones following /AS each time /AS is updated. If you run this multiple times on the same PDF you will get a buildup of detritus that would look something like this:

/V /Off
/AS /Off
/DV /Off
/V /Off
/DV /Yes
/V /Yes
/DV /Off
/V /Off

This will cause file bloat for anyone who uses fpdm repeatedly on the same file.

A better way might be to record the line numbers for /DV and /V to the "infos" array at the same place as it does for /AS and then only update them if they were already in the PDF file.

@TristanHammat-AgilisIT
Copy link

OK, I fixed this in a fork https://github.com/TristanHammat-AgilisIT/fpdm/. Not going to bother with a pull request as it has been about 1.5 years since once has been actioned. There are a couple of other changes and me tripping over my own commits here https://github.com/TristanHammat-AgilisIT/fpdm/commits/master. I will add some additional fixes if I get time.

If you test it out and have any issues, let me know. it should now update /AS, /V and /DV but only the ones that are already present in the PDF.

@libertychisasuro
Copy link

Thanks! Fix verified on latest Adobe Acrobat Pro DC as well as FireFox.

@TristanHammat-AgilisIT
Copy link

Thanks! Fix verified on latest Adobe Acrobat Pro DC as well as FireFox.

That is great to hear. As you may have seen, I ended up fixing a couple of other errors in that fork that could stop checkboxes from displaying at all or displaying the wrong state. Also fixed some deprecated PHP usage and have been using it successfully in a project ever since.

@keithslater
Copy link

keithslater commented May 28, 2021

I'm using Tristan's fork.. Has anyone run into an issue where some checkboxes will check and some won't? Definitely using the correct names and everything. Just specific checkboxes won't check even though I can manually check them.

@tertek
Copy link

tertek commented Aug 31, 2021

@TristanHammat-AgilisIT since this repo does not get updated very much how about putting your fork to its own repo and also sharing it via composer? It is a little bit of a mess otherwise to use your work in real projects.

Also can anyone confirm problems that @keithslater had?

@TristanHammat-AgilisIT
Copy link

TristanHammat-AgilisIT commented Sep 1, 2021

Hi @tertek, that is an interesting point. I will consider doing that when I have a free moment.

As for the problems @keithslater is experiencing, I am not sure what could be causing them as it could be a host of things. fpdm is not exactly bug-free, robust, up-to-date or full-featured. I believe there are also different types of PDF forms and this code only supports the simple old original ones. Here is my process for creating a form to fill out using fpdm:

  1. Use the free online pdfescape.com to add all the form fields to the PDF and give them unique names. We also lock all of the form fields so that users don't accidentally change the content. fpdm just ignores the locked status of fields and fills them out regardless when filling the form.
  2. Sometimes PDF files will have features not supported by fpdm so next, we convert the pdf files to a guaranteed editable format using free version of the pdftk (pdflabs.com) command-line tools for windows. No special arguments are required as we simply read in the PDF and write it out to a new file. Any features unsupported by fpdm should be lost from the PDF in this process.
    pdftk form.pdf output form-fixed.pdf

This is the process that we used to make all of the PDF forms for our production project. We have about 20 different PDFs with form fields and we fill them out with different data ~400 times per quarter during an automated bulk mailout. The only issue we have hit with this process is that IOS and Android PDF viewers don't seem to recognise ticked checkboxes on the PDFs, however, all tested desktop viewers render the checkboxes correctly so I haven't bothered to work out why the mobile device PDF viewers can't do the same.

@keithslater
Copy link

I ended up switching to php-pdftk which worked out great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants