SOLVING PRINTER PROBLEMS AND CUPS PROBLEMS
This article is from August 2017 and was first published in the CentOS 6 - Hardware Support Forum.
All considerations are valid for Linux in general. Only the script below may have to be
adapted to some extent for certain OP systems. The script for CentOS 7/8 will follow.
/X/ are footnotes
1 CUPS BUG
~~~~~~~~~~
In https://bugs.centos.org I described in detail that as of CentOS 6.5 printing with my
Brother MFC-8420 Postscript Printer was no longer possible.
For a lengthy period of time the bug had not been handeled. As the MFC-8420 is a commonly used
printer being in the CUPS/Linux list I was disappointed to be left without printing overnight.
So I was forced to find a solution where CUPS (origin of the bug) was no longer needed.
This is to share my investigations and my solution with CentOS/Linux users having similar
problems with printers.
2 BASIC CONSIDERATIONS
~~~~~~~~~~~~~~~~~~~~~~
Following the specs the MFC-8420 understands "PCL6" /A/ as well as "PostScript 3" /B/.
CentOS 6 / Gnome 2.28 generate "Postscript Level 2" files /C/ which I will call "y.ps" below.
So it was obvious trying to send y.ps directly to the printer assuming downward compatibility
for the printer. This was successful as described below.
3 FUNCTIONING OF CUPS
~~~~~~~~~~~~~~~~~~~~~
CUPS and its libraries are processing y.ps at the same time incorporating PPD /D/ settings.
Finally this agglomeration of data is sent to the printer. You may look at these data using /E/.
The PPD may add features like addressing a second paper tray, duplex printing, stapling, ...
CUPS' Test Page is created artificially and says little about real life.
On top of CUPS you may install a package called "hpijs-pcl5e" which converts PostScript to PCL.
Of course this can only function if your printer understands PCL. I tried this and the results
for the MFC-8420 are totally unacceptable. (As PS and PCL follow totally different technical
concepts a conversion seems to be a very daring attempt.)
4 SENDING y.ps TO THE PRINTER DIRECTLY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4.1 The printer will be connected to your computer with an USB cable. Upon connection CentOS
(version 6.9 in my case) allocates the device '/dev/usb/lp0'. Now you can do
'cat y.ps > /dev/usb/lp0' and the printer will receive y.ps. Do not forget resetting the
printer (off/on) when experimenting.
4.2 The printer is connected to a (residential) gateway, FritzBox in my case. You do
'nc -w 2 192.***.***.*** 9100 < y.ps' to make your printer receive y.ps. For 'nc' see /E/.
'192.***.***.*** 9100' is the same term CUPS would use : IP address of your router + port 9100.
Do not forget resetting the printer (off/on) when experimenting.
5 SIMPLE SCRIPT TO REPLACE CUPS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Between the '---' lines below my script is printed (personal data are *ed or .ed). The script
is in "production" since 2016. The script should function on each Linux system where
PostScript-Version-X files are generated by a print dialog AND the printer's PostScript
version is greater or equal X. "nc" below may be called "netcat", "nmap-ncat", ...
in other systems.
---------------------------------------------------------------------------------------------- # DHA 12-AUG-2017 (last change) # # note that script is called with "bash /...full path .../tr537.sh" # # this is DHA's Print Service (replacing CUPS) # postscript files $TEFI are automatically sent to the printer using nc (netcat) # # note that a PID is allocated for this script before this line is read !!! FIPI=`pgrep -f "bash /...full path .../tr537.sh"` ; set -- $FIPI if test $# -gt 1 ; then exit ; fi # do not start script again when logging off/logging on # shopt -s dotglob # include hidden files e.g. ".ps" TEFI=/...full path .../*.ps while true ; do if test -f $TEFI ; then sleep 0.2 nc -w 2 192.***.***.*** 9100 < $TEFI zenity --window-icon=/home/...full path .../print.png --notification --timeout=2 rm -f $TEFI fi sleep 0.5 done ----------------------------------------------------------------------------------------------
SCRIPT COMMENTS
~~~~~~~~~~~~~~~
this "service" is started at logon (or startup/autologon) via
"sys/pref/startup-appl" with "bash /...full path .../tr537.sh <&- &>/dev/null"
calling a script with 'bash x.sh' has some advantages and is clearer than 1.line method
note that this is no genuine Linux service/daemon
the script consumes 2 PIDs per second. I did not find any limitation to this end, patient
users may increase 0.5 s to whatever they like, killing the script may leave an orphan
the $TEFI directory is also my sceenshot place but you may define it as part of a RAM disk
the zenity statement presents a printer icon in the panel when transfer to printer is done
note that * is for possible different names of 1 file and NOT for a group of files
the "sleep 0.2" is for the case that the test is applied to an emerging file
note that test -f "$TEFI" results to FALSE in case more than 1 file *.ps would exist !
if, for any reasons, 2 files would exist nothing happens and the number of files not being
printed would increase; I did not experience such a case but it may need consideration
all being beyond the features of the normal Print-to-File menu would need scripting effort,
i.e.changing y.ps before it is sent to the printer
Of course the script shall not be run under elevated privileges.
FOOTNOTES
~~~~~~~~~
/A/ PCL, HP's Printer Command Languge (versions 1...6) is the de facto industry standard;
PCL Technical Reference Manuals are available online
/B/ Brother says 'BR-S3' where 'BR-S3' is footnoted as 'PostScript 3 Emulations'.
"LanguageLevel 3" specs are published in a 897 pages Adobe document "PostScript Language
Reference third edition" of 1999 (available online)
/C/ having GEDIT open with "x.txt" do file/print/print to file/tick 'Postscript' (Name turns
to "x.txt.ps")/set "Save in Folder"/(optionally change "Page Setup" or "Text Editor")/
hit "Print". Now you can open "/.../x.txt.ps" in GEDIT and look at it. Of course you can
generate *.ps files from all applications having a print-to-file dialog with the
'Postscript' option. Do not be surprised about the sizes of *.ps files : Even if x.txt
would just contain the letter "a" then x.txt.ps is likely more than 10 k caused by the
graphical representation. The header of these *.ps files contains "LanguageLevel: 2".
/D/ PPD = PostScript Printer Description File; specs are published in a 236 pages Adobe
document "PostScript Printer Description File Format Specification" Version 4.3 of
9 February 1996 (available online)
/E/ Follow CUPS instructions to create a printer 'TEST' using the PPD belonging to your printer
(normally published by the vendor) or any modified PPD. Tick "AppSocket/..." and enter
as connection : "socket://127.0.0.1:9100" Thus the destination is port 9100 of your own
computer and not a network place ! Use nc (=netcat=nc-1.84-24.el6.x86_64=basic repo)
from command line 'nc -l 9100 > info.txt'. Now print whatever you want using the printer
'TEST'. The raw data the printer would have received are now in info.txt.