3

When I use checkbox on pdf form, pdftk gives the following error and does not create output pdf.

Unhandled Java Exception:
Unhandled Java Exception:
java.lang.NullPointerException
at gnu.gcj.runtime.NameFinder.lookup(libgcj.so.12)
at java.lang.Throwable.getStackTrace(libgcj.so.12)
at java.lang.Throwable.stackTraceString(libgcj.so.12)
at java.lang.Throwable.printStackTrace(libgcj.so.12)
at java.lang.Throwable.printStackTrace(libgcj.so.12)

hyhr
  • 91
  • 1
  • 3
  • What are you trying to do that it is giving you the error? – divided Feb 21 '14 at 17:16
  • I am just trying to get field data and give it to fdfgen to generate fdf file. Then I am using pdftk to create output pdf. When I use only text fields, output pdf is generated properly, but with fields such as checkbox or combobox it gives the error above. – hyhr Feb 22 '14 at 18:18

1 Answers1

0

Today I am having a similar problem with Checkbox. And I also saw java.lang.NullPointerException error. After investigation, I found that it is because my fillable checkbox is using custom glyphicon ('X') as checkmark instead of default styling.

So after reading this answer https://stackoverflow.com/a/29034948/11898471, It does workout by getting rid of my custom checkbox glyphicon. Without seeing your code I don't know exactly how you may do it your way, but my situation is to flatten a client uploaded PDF form with custom checkbox. What I did, is to extract all form data and re-fill the form so they get rid of all custom checkbox markup. Something like:

            $pdf = new Pdf($uploadedFile->getRealPath(), ['command' => env('PDFTK_PATH')]);

            /* Extract form field to remove custom markup field that cannot be filled. Eg: custom checkbox icon  */
            $pdf2 = new Pdf($uploadedFile->getRealPath(), ['command' => env('PDFTK_PATH')]);
            $data = $pdf2->getDataFields();
            $data = (array) $data;
            $fill_data = [];
            foreach ($data as $field) {
                if (isset($field['FieldValue'])) {
                    $fill_data[$field['FieldName']] = $field['FieldValue'];
                }
            }
            /* Update form field */
            $pdf->fillForm($fill_data)
                ->flatten()
                ->saveAs(storage_path('app/'.$flattenedFilename));
Cheng Shi
  • 160
  • 3
  • 7
  • Would you mind filing an issue at https://gitlab.com/pdftk-java/pdftk/issues including the pdf, fdf, and error message? It should be possible to fix pdftk so that you do not need a workaround. – notautogenerated Jun 21 '20 at 08:01