codeforamerica / pdfhook

A Python web application for converting PDF forms into PDF-filling APIs
https://pdfhook.herokuapp.com
MIT License
46 stars 24 forks source link

Solve choice field errors #44

Closed bengolder closed 8 years ago

bengolder commented 8 years ago

Listbox and dropdown fields (both are FieldType: "Choice") seem to work differently on different platforms. This branch includes two tests that raise errors while trying to fill listbox and dropdown fields.

The tests in this branch currently expect errors on my local OS X 10.11 machine, but since Travis CI does not get errors with these fields, the tests do not pass remotely.

This branch should exist to resolve these issues, and can be closed by either deciding not to support those field types at this time (they do not generally exists in paper forms), or by finding a way to fill these field types consistently on multiple platforms.

Here are the expected local errors:

======================================================================
ERROR: test_fill_dropdown (tests.integration.test_pdftk.TestFields)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/bgolder/projects/pdf/pdfhook/tests/integration/test_pdftk.py", line 111, in test_fill_dropdown
    filled_pdf = pdftk.fill_pdf(path, sample_answers)
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 255, in fill_pdf
    pdf_path, patched_fdf_str)
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 245, in _load_patched_fdf_into_pdf
    'output', tmp_pdf_path
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 83, in run_command
    raise PdftkError(err.decode('utf-8'))
src.pdftk_wrapper.PdftkError: Unhandled Java Exception in create_output():
java.lang.ArrayIndexOutOfBoundsException: 0
   at pdftk.com.lowagie.text.pdf.DocumentFont.fillEncoding(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.doType1TT(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.<init>(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.getAppearance(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setField(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setFields(pdftk)

======================================================================
ERROR: test_fill_listbox (tests.integration.test_pdftk.TestFields)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/bgolder/projects/pdf/pdfhook/tests/integration/test_pdftk.py", line 99, in test_fill_listbox
    filled_pdf = pdftk.fill_pdf(path, sample_answers)
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 255, in fill_pdf
    pdf_path, patched_fdf_str)
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 245, in _load_patched_fdf_into_pdf
    'output', tmp_pdf_path
  File "/Users/bgolder/projects/pdf/pdfhook/src/pdftk_wrapper.py", line 83, in run_command
    raise PdftkError(err.decode('utf-8'))
src.pdftk_wrapper.PdftkError: Unhandled Java Exception in create_output():
java.lang.ArrayIndexOutOfBoundsException: 0
   at pdftk.com.lowagie.text.pdf.DocumentFont.fillEncoding(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.doType1TT(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.<init>(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.getAppearance(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setField(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setFields(pdftk)