OpenPrinting / libcupsfilters

Apache License 2.0
5 stars 22 forks source link

pdftopdf loses entered form data when flattening the PDF #28

Closed akorobkin closed 1 year ago

akorobkin commented 1 year ago

OS: Debian testing, cups-filters: 1.28.16-1+build3

How to reproduce:

  1. Create or find a PDF form
  2. Fill it out
  3. Save as a PDF
  4. Print via lp command.

When opened with a PDF viewer, the form will have the entered data. However, when printed, the data will be lost.

It seems that pdftopdf filter is doing this. Running cupsfilter to apply just the pdftopdf filter to a simple form.pdf file returns a flattened file with no entered data.

cupsfilter -o media=letter -o fit-to-page -o colormodel=cmyk -o pagesize=letter -p /usr/share/ppd/cupsfilters/Ricoh-PDF_Printer-PDF.ppd -m application/vnd.cups-pdf form.pdf >form-flattened.pdf

Original form.pdf and resulting form-flattened.pdf are attached.

Note how the Question 1 is still there, but the answer 444 is lost in the flattened document.

tillkamppeter commented 1 year ago

I have done a quick check and can repsoduce this bug with libcupsfilters 2.x and cups-filters 2.x, but, with the attached example, and also with data/form_english.pdf included in the libcupsfilters source repository.

I have tried with several other forms, there the filled in data does not get lost.

@jberkenbilt, @dheeraj135 it seems that there are certain form types where our current, QPDF-based flattening does not work. Could you have a look?

jberkenbilt commented 1 year ago

I've been a bit swamped but will try to find time to look at this in the next few days.

jberkenbilt commented 1 year ago

Sorry for the long delay. I have identified the issue, and it's basically a one-line change. What I need to do is figure out how we've gone this many years without having seen this before, because it seems like a really obvious mistake. I also need to make sure I have a test case for it. I'll try to get a fix in main this weekend if possible.

jberkenbilt commented 1 year ago

I'm going to work this as qpdf/qpdf#949 which is caused by the same underlying issue.

jberkenbilt commented 1 year ago

I figured out what's going on here. The PDF file in question is using the /AS key (appearance state) incorrectly, but qpdf can easily work around it.

tillkamppeter commented 1 year ago

I have installed QPDF 11.4.0 as of https://github.com/qpdf/qpdf/issues/949 now and tested the command line of the initial posting again. The new QPDF indeed fixes this bug. Closing ...

tillkamppeter commented 1 year ago

Thanks a lot for the quick fix and release, @jberkenbilt !