Monday, February 5, 2018

Fixing PDF printing problems on Ubuntu 12 04

Fixing PDF printing problems on Ubuntu 12 04


Between Ubuntu 11.10 and 12.04, a number of backend changes were made to better support the PDF workflow that the Linux and Mac communities are adopting of late. CUPS was updated from 1.5.0 to 1.5.2. Poppler is used as a PDF toolset; it was updated from 0.16.x to 0.18.x. Ghostscript is still around, but 9.05 changed some font detection behavior.

At work, we use a web vendor that provides us output from a QuarkXpress PDF software on their web server. The PDFs we get from them will not print in Google Chrome on Ubuntu 12.04 (I have bastardized CUPS 1.5.0 parts into some 11.04 installs I maintain: that seems to work). We currently use Brother and Samsung printers: the vendor uses HP, and they said that works. If their PDF is saved as a new PDF (via "print as PDF" or most conversion tools), it will print fine; otherwise, its PCL XL errors and/or 95% of the page missing.

Multiple websites and bug reports online, point towards changing the MIME types in CUPS as a solution. For me, its a half solution: disabling some conversions can yield some output; but its still only 90% complete. However, the tool to fix the output, came with 12.04: pdftocairo. Using assorted online references + hints from the weird scripts Brother uses for its own drivers (which I dont really use), I was able to make my own print filter to "wash" PDF output. Youre also supposed to be able to define your own MIME type rules: I ended up patching the default set instead.

Ive tested this modification on an HL-4040 (default driver), an HL-2140 (default driver), and a MFC-8480 (Postscript driver worked; BRScript default driver is a maybe). It is my humble suggestion that someone endeavour to make a version of pdftocairo, that can be called directly to handle print job conversions.

Update 5-29-2012: changed the script significantly to support multi-copy printing. pdfunite comes with pdftocairo.

Update 6-1-2012: someone caught a typo in one of my paths.

Procedure


1. In a terminal, sudo bash or login as root.
2. Make the /usr/lib/cups/filter/pdfwash file with your favorite text editor (nano or leafpad works).
3. Using the text editor, change the lines in the /usr/share/cups/mime/cupsfilters.convs file to look like what I posted.
4. chmod a+x /usr/lib/cups/filter/pdfwash
5. /etc/init.d/cups/restart
6. Exit the terminal.

Files


/usr/lib/cups/filter/pdfwash

#!/bin/bash
# CUPS filter to wash PDF output for printing
# Version 1.1, 5-29-2012, Michael Adams, unquietwiki.com

#jobid="$1"
#user="$2"
#title="$3"
#copies="$4"
#options="$5"
#file="$6"

# Make original copy of washed PDF
mkdir /tmp/pdfwash
temp_pdf=`mktemp /tmp/XXXXXX.pdf`
pdftocairo -q -pdf -origpagesizes $6 /tmp/pdfwash/0

# Attempt to make copies of PDF
for ((i=0;i<$4;i++)) do
   cp /tmp/pdfwash/0 /tmp/pdfwash/$i
done

# Combine and display multi-copy, else the original single copy
if [ -e "/tmp/pdfwash/1" ]
then
   pdfunite /tmp/pdfwash/* $temp_pdf
   cat $temp_pdf
else
   cat /tmp/pdfwash/0
fi

# Remove temp files
rm $temp_pdf
rm /tmp/pdfwash/*

exit 0

/usr/share/cups/mime/cupsfilters.convs

application/postscript        application/pdf            0    pstopdf
application/vnd.adobe-reader-postscript    application/vnd.cups-postscript    0    pstops
application/pdf        application/vnd.cups-pdf        0    pdfwash
application/vnd.cups-pdf-banner    application/vnd.cups-pdf    33    bannertopdf
#application/pdf        application/vnd.cups-postscript    0    pdftops
#application/vnd.cups-pdf    application/vnd.cups-postscript    0    pdftops
application/postscript        application/vnd.cups-postscript    66    pstops

Related online tickets


* Google Chrome / Brother bug
* Poppler PDF bug
* Ubuntu Brother printing bug
* Debian Brother printing bug
* Another Debian print bug


visit link download