Cannot print a PDF with AcroForms using fit-to-page

Bug #1564249 reported by Dmitry
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cups-filters (Ubuntu)
Fix Released
Undecided
Unassigned
qpdf (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Using KUbuntu 14.04. I am trying to print the attached PDF with filled forms (AcroForms) with the following command:

lpr -o fit-to-page PDFForm3.pdf

But my Samsung ML-1210 prints the document with empty forms. If I omit -o fit-to-page then all the forms keep the filled data.

----------

# lsb_release -rd
Description: Ubuntu 14.04.4 LTS
Release: 14.04

# apt-cache policy cups
cups:
  Installed: 1.7.2-0ubuntu1.7
  Candidate: 1.7.2-0ubuntu1.7
  Version table:
 *** 1.7.2-0ubuntu1.7 0
        500 http://ftp.byfly.by/ubuntu/ trusty-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main i386 Packages
        100 /var/lib/dpkg/status
     1.7.2-0ubuntu1 0
        500 http://ftp.byfly.by/ubuntu/ trusty/main i386 Packages

CUPS in Xenial (from here: http://cdimage.ubuntu.com/daily-live/current/xenial-desktop-i386.iso) has the same issue. Xenial:

# lsb_release -rd
Description: Ubuntu Xenial Xerus (development branch)
Release: 16.04

# apt-cache policy cups
cups:
  Installed: 2.1.3-3
  Candidate: 2.1.3-4
  Version table:
     2.1.3-4 500
        500 http://by.archive.ubuntu.com/ubuntu xenial/main i386 Packages
 *** 2.1.3-3 100
        100 /var/lib/dpkg/status

Revision history for this message
Dmitry (dmitrymq) wrote :
Dmitry (dmitrymq)
description: updated
Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Can you try the newest Ubuntu version (life image on USB or DVD)? Does the problem persist there?

Changed in cups (Ubuntu):
status: New → Incomplete
affects: cups (Ubuntu) → cups-filters (Ubuntu)
Changed in qpdf (Ubuntu):
status: New → Incomplete
Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Most probably this is a QPDF problem. QPDF is the PDF processing library used by pdftopdf, the filter which processes fit-to-page.

Created an upstream bug report on QPDF:

https://github.com/qpdf/qpdf/issues/72

Revision history for this message
Dmitry (dmitrymq) wrote :

Till Kamppeter (till-kamppeter),

I tested in Xenial too (see the head message), and it has the same issue. However I cannot use Xenial since I cannot upgrade from 14.04 for some specific reasons.

Revision history for this message
Tobias Hoffmann (smilingthax) wrote :

See https://bugs.linuxfoundation.org/show_bug.cgi?id=1315 why this cannot work.
And QPDF won't be able to do anything about it, either...
There might even be PDF-capable printers on the market (i.e. where the rasterization is not done by gs / poppler on the host), where the form content will not be printed even without the fit-to-page option.

The PDF format generally does not allow arbitrary transformations (as used by pdftopdf in certain cases) to be applied to the ("interactive") Form content - which is stored separately from the Page content.
The usual solution for printing is that the viewer application (Evince, Google Chrome, ...) converts (hard-codes) any Form content into regular Page content before sending the data to the printing chain. Using lpr skips this (non-trivial) step.

Revision history for this message
Tobias Hoffmann (smilingthax) wrote :

For example, here some java/PDFBox-based implementation of how to flatten simple forms:
 https://gist.github.com/jribble/beddf7620536939f88db
(IIRC there are more form elements than those 2-3 handled here(?)).

Note that QPDF does not have something like the PDAcroForm class (and its friends) used there to easily access the form data. So any QPDF/C++ based form flattener has to implement that, too.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Dmitry, can you print your filled-form PDF when opening it in a PDF viewer (evince, some KDE viewer, ...) set fit-to-page in the printing options in the print dialog and print? The viewers usually re-generate the PDF in a simpler way with the interactive forms replaced by static PDF content and send that to the printing subsystem.

Try also

ps2pdf PDFForm3.pdf - | lpr -o fit-to-page

ps2pdf runs your PDF through Ghostscript, which also re-generates it in a static form.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

I have done the tests of my previous comment with the attached file and printing this way works, meaning that both evince and Ghostscript re-generate the PDF file for printing, so that a static file is sent.

A point of improvement for cups-filters would be here to let pdftopdf somehow recognize that the incoming PDF has non-static content and if so, running it through some Ghostscript/Poppler/MuPDF command line utility for flattening the file into a completely static one.

Changed in cups-filters (Ubuntu):
status: Incomplete → Triaged
Changed in qpdf (Ubuntu):
status: Incomplete → Triaged
Revision history for this message
Dmitry (dmitrymq) wrote :

I'll try pdf2ps (did you mean that?). I cannot try any of X11 applications since X11 is not installed there and I have no control over that.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

I meant ps2pdf, as ps2pdf generates PDF. It was originally made for converting PostScript to PDF, but it works also with PDF as input as Ghostscript accepts also PDF as input. This way it converts PDF (non-static) to PDF (static). So use ps2pdf as shown in my comments above.

Revision history for this message
Jay Berkenbilt (ejb) wrote :

If I'm reading this correctly, it looks like there's no short-term change to qpdf required. Is that correct? I'm thinking doing this type of flatting in qpdf is probably out of scope, but in any case, I wouldn't have time to work on it any time soon. I haven't studied interactive forms enough to know exactly what would be involved.

There are certainly limitations of just directly printing PDF, and it's unlikely that qpdf or a filter that only does structural transformation will ever be able to handle all these kinds of issues.

If I've misread this and there is something expected to be done with qpdf in the short term, please clarify so I don't inadvertently decide not to do something that needs to be done. Thanks.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Jay, QPDF could be used for identifying whether a file contains forms or not. See

https://bugs.linuxfoundation.org/show_bug.cgi?id=1315

nad there comment #9 with the link to

https://github.com/smilingthax/pdfformflatten

This code identifies PDFs with forms but does not actually flatten them. pdftopdf could use this and if a form is found pass the PDF through Ghostscript/Poppler/MuPDF to flatten it and after that do the usual QPDF treatment of pdftopdf.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Jay, would you be able to add PDF form flattening functionality like implemented in

https://gist.github.com/jribble/beddf7620536939f88db

into QPDF? Or is a real PDF interpreter (Ghostscript, Poppler, MuPDF) needed for this?

Revision history for this message
Dmitry (dmitrymq) wrote :

The trick with ps2pdf works fine. I am able to convert to a static PDF and then print it with fit-to-page.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Jay, what about implementing PDF form flattening in QPDF? As suggested in comment #13?

Revision history for this message
Jay Berkenbilt (ejb) wrote :

I'll have to study it. Sorry, I have been quite starved for time to work on qpdf. I would like to fix this, but I can't commit to a timeframe.

Changed in cups-filters (Ubuntu):
status: Triaged → Fix Committed
Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

For the time being (cups-filters 1.17.4) I have now applied a solution where pdftopdf detects PDF forms using QPDF (thanks to Tobias Hoffmann, smilingthax) and if there is a form uses and external utility for the flattening, preferrably pdftocairo, if not present, Ghostscript. After the flattening the original treatment by QPDF is performed.

If none of the utilities is available, no form-flattening is performed (but as cups-filters-core-drivers depends on poppler-utils, pdftocairo is always there).

The originally planned QPDF-based solution is still in the works and will most probably added in a later release of cups-filters. Therefore the QPDF task stays open.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cups-filters - 1.17.4-0ubuntu1

---------------
cups-filters (1.17.4-0ubuntu1) artful; urgency=medium

  * New upstream release
    - pdftopdf: If the input PDF file contains an interactive
      form, flatten it to static PDF so that further manipulation,
      like scaling, number-up, ... do not let the filled for
      content getting lost. This is implemented by using the
      pdftocairo utility of Poppler and if this fails Ghostscript
      (9.22 or later recommended). This will probably replaced by
      a QPDF-based solution later. Thanks to Tobias Hoffmann for
      the QPDF-based detection of PDF forms (Upstream bug #1315,
      LP: #1564249).

 -- Till Kamppeter <email address hidden> Sun, 10 Sep 2017 16:14:50 -0300

Changed in cups-filters (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Jay Berkenbilt (ejb) wrote :

I think this bug can be closed now, right?

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Yes, the QPDF task is now done, too. Thank for all the hard work on this, Jay.

Changed in qpdf (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.