Latest Tweets

CUPS: After printing some PDFS, the printer queue stops working completely.

The issue

After printing certain PDFS using CUPS on an Ubuntu GNU/Linux Lucid box, the entire printer queue stops working, issuing an stopped: “/usr/lib/cups/filter/pstopdf failed” error message.

Cups error log

First of all, CUPS does have an error log. It is extremely important to be able to understand what’s going on behind the scenes on every single program. GNU/Linux does indeed facilitate this. Whenever an error message shows up on the CUPS web-page or gnome front-end, a more detailed and specific error can be read from the /var/log/cups/error_log file. It is of paramount importance to determine beforehand the job-id that caused the printer queue to stop working in order to look for its associated error messages in the log file. Thus, in our particular case we had an error after trying to print a PDF document with assigned job-id 2192, as clearly shown below:

cups_error_job

jod-id 2192, firing a backend error and stopping the printer queue.

Reading through the /var/lib/cups/error_log file, and filtering by the job-id, that is, 2192, we came to find a ghost-script error message:

    'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Error: /undefined in BEVFAF+TimesNewRomanPSMT*1',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Operand stack:',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192]',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Execution stack:',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1878   1   3   %oparray_pop   1877   1   3   %oparray_pop   1861   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Dictionary stack:',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] --dict:1165/1684(ro)(G)--   --dict:1/20(G)--   --dict:81/200(L)--   --dict:57/75(L)--   --dict:211/313(L)--   --dict:72/140(L)--   --dict:12/20(G)--   --dict:0/10(L)--   --dict:12/50(ro)(G)--   --dict:56/71(L)--',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Current allocation mode is local',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] Last OS error: 2',
               'D [16/Jan/2013:12:39:17 +0100] [Job 2192] GPL Ghostscript 8.71: Unrecoverable error, exit code 1',
               'D [16/Jan/2013:12:39:17 +0100] PID 32605 (/usr/lib/cups/filter/pstopdf) stopped with status 1!',

The first line of the previous error log message shows what sort of error fired the ghost-script execution stack. According to its documentation, this error message happens because there is an unknown object – in this case a font – that cannot be processed by the Ghost Script tool. In concordance with this error message, there is a font called TimesNewRomanPSMT that cannot be processed. Thus, the ghost-script ends its execution with an error and the /var/lib/cups/filter/pstopdf filter cannot continue either, ending its own execution as well. Therefore, it immediately follows that the job cannot be printed.

This issue seemed quite related to this one I analysed some time before.

Therefore, I used the pdffonts utility to determine if this particular font was or was not embedded in the original PDF document:

Times-Roman                          Type 1            no  no  no     145  0

So, the conflictive font was not embedded in the PDF. The error was quite explicit, and by using pdffonts, we could work out precisely so. Thus, we were in need of embedding that particular font, so that ghost-script did not complain about it. We decided to have a look at the way CUPS called ghost-script, to speed up things a bit. Again, we looked for this in the /var/log/cups/error_log file,  filtering by the job-id, and so:

 ‘D [16/Jan/2013:12:39:14 +0100] [Job 2192] Running cat | /usr/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dAutoRotatePages=/None -dAutoFilterColorImages=false                -dNOPLATFONTS -dPARANOIDSAFER -sstdout=%stderr -dColorImageFilter=/FlateEncode                 -dPDFSETTINGS=/printer                 -dColorConversionStrategy=/LeaveColorUnchanged -dDoNumCopies -r600 -dDEVICEWIDTHPOINTS=595 -dDEVICEHEIGHTPOINTS=842 -sOutputFile=-  -c .setpdfwrite -f -‘,

We wrote a simple bash-script to generate the PS file from the PDF one by running the very same command, and then we ran the ps2pdf file to get back to a PDF version. Our idea was to ensure that every single font, in doing so, would be embedded in the resulting PDF file. Here is our script:

#!/bin/bash
if [ $# -ne 1 ]; then
        echo "Usage: `basename $0` infile.pdf"
        exit 0
fi
 
INFILE="$1"
OUTFILE="fixed-`basename $INFILE .pdf`.ps"
GS=/usr/bin/gs
PS2PDF=/usr/bin/ps2pdf
 
# Run gs:
$GS -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dAutoRotatePages=/None -dAutoFilterColorImages=false \
       -dNOPLATFONTS -dPARANOIDSAFER -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/printer -dColorConversionStrategy=/LeaveColorUnchanged \
       -dDoNumCopies -r600 -dDEVICEWIDTHPOINTS=595 -dDEVICEHEIGHTPOINTS=842 -sOutputFile=$OUTFILE $INFILE
 
if [ $? -eq 0 ]; then
        # Convert once again to pdf:
        $PS2PDF $OUTFILE && echo "`basename $OUTFILE .ps`.pdf has been created. Try to print now..."
        # Remove the ps
        rm -f $OUTFILE
fi

After writing it, we ran the script in order to convert the PDF file we were having trouble with this way:

./fix_pdf.sh file_with_trouble.pdf

The resulting PDF file did have the missing font:

PMCDFQ+Times-Roman                   Type 1C           yes yes no       9  0

We tried to print it once again and it worked. For any other troublemakers PDF files with missing fonts, our script turned out to be helpful too. If you are experiencing problems like this one, try and use our script and let us know.