add/remove the PDF printer in CUPS at installation/removal time

Bug #82674 reported by Christian Wolf
6
Affects Status Importance Assigned to Milestone
cups-pdf (Ubuntu)
Fix Released
Medium
Till Kamppeter

Bug Description

Binary package hint: cups-pdf

In order to fulfill a popular feature request (PDF printing as default), the package cups-pdf needs to be added as requirement to the package ubuntu-desktop. For this reasons, the PDF queue needs to be added/cleared during install/uninstall of cups-pdf.

See Launchpad for more details:

https://blueprints.launchpad.net/ubuntu/+spec/pdf-printing-cups-as-default

Corresponds to Bug #82671

Revision history for this message
Martin-Éric Racine (q-funk) wrote :

Exactly what do you mean by PDF queue? Can you refer to a specific directory or file?

Revision history for this message
Christian Wolf (christianwolf) wrote :

I *think* the person who added this to the feature request means that there should be a printer device / printer queue automatically selected and installed after having installed cups-pdf and removed when un-installing the package.

Currently, as far as I know (have not checked feisty yet), you first have to install cups-pdf and then you need to go to the printer setup and select the printer-device from the list etc.

In order to have a PDF printing functionality as default, this last step (selecting and activating the PDF printer device) needs to be scripted. The perfect solution would be IMHO to check first if there is another printer device already installed. If no, make PDF printer the default printer; if yes, just install it but keep the existing printer as the default printer.

Read here how complicated it is to use the PDF printing functionality the first time. I think that still fails the grandmother test :-)

https://help.ubuntu.com/community/PDFPrinting?action=show&redirect=forum%2Fsoftware%2Fcups-pdf
http://www.ubuntuforums.org/showthread.php?t=188860

Revision history for this message
Martin-Éric Racine (q-funk) wrote :

Right, so you meant that CUPS-PDF should automatically add the PDF printer in CUPS at installation time and delete it at removal time.

While this is doable, using postinst and prerm maintainer scripts, there are disadvantages to this method:

1) Users might want to use a PPD other than the default one.

2) Automatically making this printer the default is not desirable in cases when the user also has a real printer attached to their system. We want to let the user freely choose which one should be the default.

I'd really like the input of the Ubuntu printing team on how to approach this request.

PS: the instructions you linked to really point to CUPS itself failing the grandmother test. :)

Revision history for this message
Martin-Éric Racine (q-funk) wrote :

Renamed from
"Let post-install create and pre-uninstall remove the PDF queue"
to
"add and remove the printer in CUPS at installation/removal time".

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

There should be a special print queue for generating PDF files. Sending a job to this queue should generate a PDF file from the document sent into the queue. The PDF file should be easily accessible for the sender of the job, but other users should not be able to read it.

The package cups-pdf provides the special CUPS backend which converts incoming PostScript to PDF and puts the resulting PDF into the right place.

To make this grandmother-proof, the installation of the package should prepare everything to use this feature. Especially the mentioned print queue is needed. As the package does not make sense without the print queue and the print queue does not make sense without the package, the queue should be created when the package finishes to be installed (postinstall) and the queue should be removed when the package starts to be uninstalled (prerm).

Creating and taking down the queue in the postinstall and prerm scripts is easy. To create it do

lpadmin -p PDF -E -v cups-pdf:/ -m foomatic:Generic-PostScript_Printer-Postscript.ppd -o PageSize=A4

and to take it down

lpadmin -x PDF

This should be somewhat refined, once when creating the queue it should be checked whether the queue name already exists and if so, another queue name should be used (PDF1, PDF2, ...). If there is already a queue with a "cups-pdf:/" URI, no queue shoud be created.

On uninstallation of the package all queues with "cups-pdf:/" URIs should be taken down.

A script can also easily find out which local queues already exist and which URI they have:

lpstat -v | grep -v 'ipp://'

It should also be checked whether a default printer or class is set ("lpstat -d") and if not, the new PDF queue should be made the default.

Concerning the user's choice of the PPD file, he can always change it with any printer setup tool. More important is grandmother-proofness and this one reaches only by using a default PPD file.

The PPD file needed is one for a generic PostScript printer. Best is one which has no tray and duplex options (there is no printer), no resolution (both PostScript and PDF are vector formats and there is no raster-based printing engine). It should have only things like color/bw, quality vs. size, ... (see what options you can set when choosing "Export to PDF" in OpenOffice.org).

Changed in cups-pdf:
importance: Undecided → Medium
status: Unconfirmed → Confirmed
Revision history for this message
Martin-Éric Racine (q-funk) wrote :

Till, thanks for your overview of the situation.

CUPS-PDF already provides a generic PostScript PPD which upstream and I heavily edited to include only the bare minimum.

We could indeed create a printer called PDF at installation time and delete it at removal time, then restart CUPS to refresh the available printer list.

Detecting all existing CUPS-PDF devices at installation and removal is slightly more tricky and would require a heavy dose of scripting magic. Patches are welcome.

Making CUPS-PDF the default CUPS printer could be done, but might confuse users who have real printers attached to their computer and make them wonder why printouts are not coming out of their printer by default.

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

Such a PDF printer makes only sense one the local machine, where the printer queue is defined, therefore CUPS should be advised to no broadcast it into the network. This is done by adding "-o printer-is-shared=no" to the "lpadmin" command:

lpadmin -p PDF -E -v cups-pdf:/ -m foomatic:Generic-PostScript_Printer-Postscript.ppd -o PageSize=<A4 or Letter depending on locale> -o printer-is-shared=no

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

Detecting all cups-pdf devices is easy, to take down all these queues simply do

for q in `LC_ALL=C lpstat -v | grep 'cups-pdf:/' | cut -d ':' -f 1 | cut -d ' ' -f 3`; do
   lpadmin -x $q
done

For setting the PDF printer as default check at first whether there is already a default printer with "LC_ALL=C lpstat -d | grep 'system default destination:'" and set PDF as the default printer only if there is no default printer yet.

You do not restart CUPS when adding or removing printers with the "lpadmin" command.

Revision history for this message
Martin-Éric Racine (q-funk) wrote :

The script magic you propose for prerm should work well as-is.

For postinst, what I would use:

lpadmin -p PDF -E -v cups-pdf:/ -m PostscriptColor.ppd -o PageSize=$(paperconf) -o printer-is-shared=no

paperconf(1) from libpaper-utils (added to Depends) tells us the default paper size.

What I need before that is a way to check:

1) Is there already a printer called PDF? if there is, add a digit to the printer name we're about to create.

2) Is there any default printer already? If there is, don't set as default.

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

Steps for Post-install:

Check whether there is already a CUPS-PDF queue with "LC_ALL=C lpstat -v | grep 'cups-pdf:/'". If so, assign the name of the first queue found to $queue and skip the next paragraph.

Assign "PDF" to the variable $queue, then start a "while" loop checking "LC_ALL=C lpstat -v | cut -d ':' -f 1 | cut -d ' ' -f 3 | grep ^$queue\$" and exit the "while" loop if it fails. In the while loop asign a new name to $queue: PDF, PDF1, PDF2, ... Then create the queue with queue name $queue.

Then check with "LC_ALL=C lpstat -d | grep 'system default destination:'" whether there is already a default printer. If not, set the PDF printer as default with "lpadmin -d $queue".

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

Note that with "-m" in the "lpadmin" you have to give the PPD path exactly as shown in the output of "lpinfo -m". If you want to give an absolute path, use "-P" (uppercase P) instead.

Changed in cups-pdf:
assignee: nobody → q-funk
Revision history for this message
Martin-Éric Racine (q-funk) wrote :

Note that CUPS-PDF 2.4.6-1 (Gutsy) already performs a fair dose of auto-detection. Adding the printer is now only a two-click process. Not quite the fully automated installation, but almost.

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

Packages for testing are here:

http://www.linux-foundation.org/~till/tmp/ubuntu/gutsy/cups-pdf/

Will soon appear in Gutsy.

Changed in cups-pdf:
assignee: q-funk → till-kamppeter
status: Confirmed → Fix Committed
Revision history for this message
Martin-Éric Racine (q-funk) wrote :

I'd appreciate the diff being submitted directly to Debian to avoid pointless forks and instead make everyone benefit from it. Thanks!

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

I have attached a debdiff of my changes now. This should help you to add the changes to the Debian package.

Changed in cups-pdf:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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