fpdm
fpdm copied to clipboard
checkbox does not display in acrobat reader
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;
I can confirm this fixes the display error for acrobat. Thx @fabboyrie
thanks!
Can you submit a pull request?
Done https://github.com/codeshell/fpdm/pull/42
It's my first pull request, I hope I made no mistakes.
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.
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.
Thanks! Fix verified on latest Adobe Acrobat Pro DC as well as FireFox.
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.
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.
@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?
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:
- 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.
- 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.
I ended up switching to php-pdftk which worked out great