LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Printing problems (https://www.linuxquestions.org/questions/linux-newbie-8/printing-problems-4175635096/)

giancarlo64 07-28-2018 12:40 AM

Printing problems
 
Hi to all,
In order to gradually eliminate my fax I have written a bash script that print automatically an email with or without attachment. The sctipt do the following job:
1) Every 5 min check automatically for an emails (external email account)
2) Download it one by one and convert the plain text/html in a postscript file and save it in a folder. If there is an attachment (like a jpg or PDF) it extract it from the email and save it in the same folder as pdf.
3) Send to the printer (lp command) the saved files.
4) Delete the files
5) Send an email to inform that an email was received and inform of the printing status

To do the job I use a raspberry PI.
This script runned well with Raspbian Jessy until last month I noticed that some PDF couldn't be printed correctly. Reading Debian information I need to upgrade a hplip package but a new one was included only in raspbian 9. So I upgraded to version 9 but now I have more problems. Here a list of it.
1) I had to put in my script a sleep command of 5-10 second in the loop that read the saved files and send it for printing. If not only the first file will be printed, the other will be lost(where?) also if they are sent correctly to the printer (I can see the job in cups and also in the printer log)
2) CUPS now indicate all the printed and also the not printed jobs as "canceled" and no more as "completed". Why?
3) Most of the time only a part of a page of the whole pdf or plain txt files will be printed (half a page or so). The rest of the page and the additonal pages will not be printed. If I view the .ps or .pdf the files are not corrupted.

Any ideas how to start solve this problem?

Thanks

Gian Carlo

ferrari 07-28-2018 06:21 PM

Welcome to LinuxQuestions.org Gian Carlo.

Does a test page print ok?
Code:

hp-testpage
Quote:

So I upgraded to version 9 but now I have more problems. Here a list of it.
1) I had to put in my script a sleep command of 5-10 second in the loop that read the saved files and send it for printing. If not only the first file will be printed, the other will be lost(where?) also if they are sent correctly to the printer (I can see the job in cups and also in the printer log)
2) CUPS now indicate all the printed and also the not printed jobs as "canceled" and no more as "completed". Why?
Can you share the script with us?

ferrari 07-28-2018 06:30 PM

Also, with respect to the hplip environment, check that all is well on your new install...
Code:

hp-check -t

giancarlo64 07-30-2018 02:05 AM

Hi Ferrari,
thanks for your reply. Here the answer of the commands:

hp-testpage


HP Linux Imaging and Printing System (ver. 3.16.11)
Testpage Print Utility ver. 6.0

Copyright (c) 2001-15 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

error: No device found that support this feature.
error: No installed printers found (or) Invalid printer device selected

hp-check -t


error: avahi-utils avahi-utils OPTIONAL - - MISSING 'avahi-utils needs to be installed'
scanimage scanimage - Shell scanning program OPTIONAL 1.0 1.0.25 OK -
error: dbus DBus - Message bus system REQUIRED - 1.10.26 MISSING 'DBUS may not be installed or not running'
gs GhostScript - PostScript and PDF language interpreter and previewer REQUIRED 7.05 9.20 OK -
error: xsane xsane - Graphical scanner frontend for SANE OPTIONAL 0.9 - MISSING 'xsane needs to be installed'
network network -wget OPTIONAL - 1.18 OK -
error: cups CUPS - Common Unix Printing System REQUIRED 1.1 - INCOMPAT 'CUPS may not be installed or not running'
policykit PolicyKit - Administrative policy framework OPTIONAL - 0.105 OK -

----------------------
| Scan Configuration |
----------------------

scanext Scan-SANE-Extension REQUIRED - 3.16.11 OK -'/etc/sane.d/dll.d/hpaio' not found.
hpaio HPLIP-SANE-Backend REQUIRED - 3.16.11 OK 'hpaio found in /etc/sane.d/dll.conf'

---------------------
| Python Extentions |
---------------------

cupsext CUPS-Extension REQUIRED - 3.16.11 OK -
hpmudext IO-Extension REQUIRED - 3.16.11 OK -

------------------------
| General Dependencies |
------------------------

error: libusb libusb - USB library REQUIRED - 1.0 MISSING 'libusb needs to be installed'
python3X Python 2.2 or greater - Python programming language REQUIRED 2.2 3.5.3 OK -
error: python3-pyqt4-dbus PyQt 4 DBus - DBus Support for PyQt4 OPTIONAL 4.0 - MISSING 'python3-pyqt4-dbus needs to be installed'
error: python3-devel Python devel - Python development files REQUIRED 2.2 3.5.3 MISSING 'python3-devel needs to be installed'
error: libjpeg libjpeg - JPEG library REQUIRED - - MISSING 'libjpeg needs to be installed'
error: sane-devel SANE - Scanning library development files REQUIRED - - MISSING 'sane-devel needs to be installed'
error: cups-devel CUPS devel- Common Unix Printing System development files REQUIRED - - MISSING 'cups-devel needs to be installed'
python3-reportlab Reportlab - PDF library for Python OPTIONAL 2.0 3.3.0 OK -
error: cups-image CUPS image - CUPS image development files REQUIRED - - MISSING 'cups-image needs to be installed'
sane SANE - Scanning library REQUIRED - - OK -
error: libcrypto libcrypto - OpenSSL cryptographic library REQUIRED - 1.1.0 MISSING 'libcrypto needs to be installed'
error: libnetsnmp-devel libnetsnmp-devel - SNMP networking library development files REQUIRED 5.0.9 - MISSING 'libnetsnmp-devel needs to be installed'
error: python3-pyqt4 PyQt 4- Qt interface for Python (for Qt version 4.x) REQUIRED 4.0 - MISSING 'python3-pyqt4 needs to be installed'
python3-dbus Python DBus - Python bindings for DBus REQUIRED 0.80.0 1.2.4 OK -
libpthread libpthread - POSIX threads library REQUIRED - b'2.24' OK -
python3-xml Python XML libraries REQUIRED - 2.2.0 OK -
python3-pil PIL - Python Imaging Library (required for commandline scanning with hp-scan) OPTIONAL - 1.1.7 OK -
error: python3-notify2 Python libnotify - Python bindings for the libnotify Desktop notifications OPTIONAL - - MISSING 'python3-notify2 needs to be installed'

--------------
| COMPILEDEP |
--------------

make make - GNU make utility to maintain groups of programs REQUIRED 3.0 4.1 OK -
gcc gcc - GNU Project C and C++ Compiler REQUIRED - 6.3.0 OK -
error: libtool libtool - Library building support services REQUIRED - - MISSING 'libtool needs to be installed'

------------------------------
| DISCOVERED SCANNER DEVICES |
------------------------------

No Scanner found.

--------------------------
| DISCOVERED USB DEVICES |
--------------------------

No devices found.

---------------------------------
| INSTALLED CUPS PRINTER QUEUES |
---------------------------------


HP_Color_LaserJet_CM2320nf_MFP
------------------------------
Type: Unknown
Device URI: socket://192.168.6.35
PPD: /etc/cups/ppd/HP_Color_LaserJet_CM2320nf_MFP.ppd
warning: Failed to read /etc/cups/ppd/HP_Color_LaserJet_CM2320nf_MFP.ppd ppd file
PPD Description:
Printer status: printer HP_Color_LaserJet_CM2320nf_MFP is idle. enabled since Wed 25 Jul 2018 15:05:40 UTC
warning: Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.

HP_HP_Color_LaserJet_CM2320nf_MFP
---------------------------------
Type: Unknown
Device URI: dnssd://HP%20Color%20LaserJet%20CM2320nf%20MFP%20(03AC46)._pdl-datastream._tcp.local/
PPD: /etc/cups/ppd/HP_HP_Color_LaserJet_CM2320nf_MFP.ppd
warning: Failed to read /etc/cups/ppd/HP_HP_Color_LaserJet_CM2320nf_MFP.ppd ppd file
PPD Description:
Printer status: printer HP_HP_Color_LaserJet_CM2320nf_MFP is idle. enabled since Fri 20 Jul 2018 13:01:45 UTC
warning: Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.


--------------
| PERMISSION |
--------------


-----------
| SUMMARY |
-----------

Missing Required Dependencies
-----------------------------
error: 'libdbus-1-dev' package is missing/incompatible
error: 'cups' package is missing or 'cups' service is not running.
error: 'libcups2' package is missing/incompatible
error: 'libusb-1.0.0-dev' package is missing/incompatible
error: 'python3-dev' package is missing/incompatible
error: 'libjpeg62-turbo-dev' package is missing/incompatible
error: 'libsane-dev' package is missing/incompatible
error: 'libcups2-dev' package is missing/incompatible
error: 'cups-bsd' package is missing/incompatible
error: 'cups-client' package is missing/incompatible
error: 'libcupsimage2' package is missing/incompatible
error: 'libcupsimage2-dev' package is missing/incompatible
error: 'libssl-dev' package is missing/incompatible
error: 'libsnmp-dev' package is missing/incompatible
error: 'snmp' package is missing/incompatible
error: 'python3-pyqt4' package is missing/incompatible
error: 'gtk2-engines-pixbuf' package is missing/incompatible
error: 'libtool' package is missing/incompatible
error: 'libtool-bin' package is missing/incompatible

Missing Optional Dependencies
-----------------------------
error: 'avahi-utils' package is missing/incompatible
error: 'xsane' package is missing/incompatible
error: 'python3-dbus.mainloop.qt' package is missing/incompatible
error: 'python3-notify2' package is missing/incompatible

Total Errors: 16
Total Warnings: 2


Here my code:

Code:

#!/bin/bash
# versione V1.0  first version 08.12.2016
# versione V1.1  14.12.2016:  check if printer is online. Send Email if printer is offline
# versione V1.2  27.12.2016: added watchdog feature. Script write on a file chacked by a watchdog. If fie is not overwritten every 5 min system will be resetted
# versione V1.3  23.8.2018: some PDF will not be printed: upgraded to debian 9 (before 8) now all PDF are not seen as corrupted
#                Problems with version 9. Not all file are printed if sended together. Need a timeout between every page. Still problem on printing

SUPPORTED_FILETYPES=".pdf.jpg.png.tif.gif"
LP_OPTIONS="-o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100"

MAIL_ADDRESS1="myorders@mydomain.ch"
MAIL_ADDRESS="info@mydomain.ch"
MAILFILE=~/mailtemp/$(date +%F%H%M%S).eml
WD_FILE=~/watchdog_file.txt
TEMP_FOLDER=~/temp
PRINT_FOLDER=~/printable
# write to a file to reset watchdog
cat <<EOF > $WD_FILE
reset_wd
EOF

/usr/bin/fetchmail --bsmtp $MAILFILE -s --fetchlimit 1
if [[ $? = "0"  || $? = "13" ]]; then
        # EXIT CODE of fetchmail is 0 if only one msg and 13 if there is more msgs
        # /usr/bin/uudeview +e $SUPPORTED_FILETYPES -p $PRINT_FOLDER -i $MAILFILE
        ripmime -i $MAILFILE -v -d $PRINT_FOLDER
        PRINTED="no"
        HTML_FILE="no"

        #delete all file that are not  necessary
        cd $PRINT_FOLDER
        for f in textfile*
        do
            if grep -q "This is a multi-part message in MIME format" "$f"; then
                rm "$f"
                continue
            fi
            if [[ $(file --mime-type -b "$f") == text/html ]]; then
              html2ps "$f" > "000_intestazione$f.ps" 2>/dev/null
              rm  "$f"
              HTML_FILE="yes"
            fi
        done

        # join all txt files in one file

        if [ "$HTML_FILE" = "no" ]; then
            cat textfile* >> all.txt
        fi
        rm textfile* 2>/dev/null
        cd ..

        for f in $PRINT_FOLDER/*
        do
                if [ "$f" != "$PRINT_FOLDER/*" ]; then
                        LP_OUTPUT=$(lp $LP_OPTIONS "$f")
                        if [ "$?" != "0" ]; then
                                MAILTEXT="File $f could not be printed."
                                echo "$MAILTEXT" | mail -s "Print-Error" $MAIL_ADDRESS
                        fi
                        rm "$f"
                        PRINTED="yes"
                else
                        if [ "$PRINTED" = "no" ]; then
                                echo "No printable Attachments" | mail -s "Print-Error" $MAIL_ADDRESS
                        fi
                fi
                #  sleep added when upgraded to debian 9
                sleep 25
        done
        if [ "$PRINTED" = "yes" ]; then
              # remove the first 3 lines of the file because the sender will not be recognized as belonging to the email group
              tail -n +4 $MAILFILE > "$MAILFILE.tmp"
              # remove all the lines that start with "From". If not same error as the line before
              sed '/^From/ d' < "$MAILFILE.tmp" > $MAILFILE
              #define the email sender if not the email won't start
              export EMAIL=info@mydomain.ch
              mutt -s "Order received and printed" -a $MAILFILE -- $MAIL_ADDRESS1
              rm $MAILFILE
        fi
fi


ferrari 07-30-2018 05:47 PM

The printer backend is wrong (for HPLIP printer)...
Code:

HP_Color_LaserJet_CM2320nf_MFP
------------------------------
Type: Unknown
Device URI: socket://192.168.6.35
PPD: /etc/cups/ppd/HP_Color_LaserJet_CM2320nf_MFP.ppd
warning: Failed to read /etc/cups/ppd/HP_Color_LaserJet_CM2320nf_MFP.ppd ppd file
PPD Description:
Printer status: printer HP_Color_LaserJet_CM2320nf_MFP is idle. enabled since Wed 25 Jul 2018 15:05:40 UTC
warning: Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.

Remove the printer, and reconfigure with 'hp-setup'.

giancarlo64 08-01-2018 01:00 AM

Hi Ferrari,
I have deleted all the printers and run the hp-setup command in interactive mode ( hp-setup -i IP-Address) because I have no X server on the PI.
Now it seems all working. I will check next days more in details.
But why it doesn't work when I install the driver from cups?
An all the other errors from command "hp-check -t". Do I have to fix it?

Thanks 4 your help
Regards

Gian Carlo

ferrari 08-01-2018 05:12 AM

Good to read that the HP printer is now working. HP printers supported by HPLIP can be configured directly via the CUPS web interface but the appropriate backend and drivers need to be selected. It’s easier just to use the HPLIP tools.

If it’s working, don’t worry about the dependency issues, most are due to ‘over-cautious’ versioning checks. It is possible to use ‘hp-doctor’ to help lresolve some issues automatically, but I don’t think that’s needed here.

giancarlo64 08-02-2018 04:56 AM

Hi again Ferrari,
I have made some tests and in PDF I noticed that if the the page is landscape and not portrait, only a part of the landscape page will be printed. I have a PDF with 3 pages and the second is landscape. It will be printed only a part of it. The 1st and the 3rd are printed ok.
I noticed also that in this PDF cups tell me that the state is canceled

What could be?

Gian Carlo

ferrari 08-03-2018 02:55 AM

Which application are you using here? I've never tried printing a multi-page document containing both landscape and portrait pages. I do recall long discussions and bug reports about how CUPS should handle page orientation/roatation/scaling etc. I haven't encountered any issues over the past few years (but my printing requirements are modest). Out of interest how is this 3-page documented reported by pdfinfo (part of poppler-tools)?
Code:

pdfinfo /path/to/your/file.pdf
What happens if you try to print the 2nd page on it's own?

Is there a print dialogue option to adjust scaling with 'fit to paper' or similar?

giancarlo64 08-03-2018 06:32 AM

1 Attachment(s)
Hi Ferrari,
the pdfinfo command give me the following result:

CreationDate: Tue Jul 31 16:54:08 2018 UTC
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 3
Encrypted: no
Page size: 595.08 x 841.68 pts
Page rot: 0
File size: 653560 bytes
Optimized: no
PDF version: 1.4

In the attachment you can find the error log file of cups. I eliminated the rest and job 1999 is the PDF job.
argv[5] are "finishings=3 fit-to-page media=A4,tray1 number-up=1 position=top scaling=100 job-uuid=urn:uuid:022e0d6b-5c40-3268-67ea-132f244af901 job-originating-host-name=localhost date-time-at-creation= date-time-at-processing= time-at-creation=1533193228 time-at-processing=1533193228 document-name-supplied=doc04408120180731165353.pdf PageSize=A4"
I can't see critical errors in printing the pdf.

Gian Carlo

ferrari 08-03-2018 04:43 PM

Yes, the error log looks as expected. The CUPS filter chain is pdftopdf > pdftops > application/vnd.cups-postscript, and it is here where any rotataton and/or scaling takes place. A bug report may be needed here. Again, which PDF viewing application is involved here?

AwesomeMachine 08-04-2018 04:29 AM

Ever since Apple stopped development of cups for Linux, the cups-filters package has had problems that can only be solved by the new Linux cups development team via bug reports.

giancarlo64 08-05-2018 03:21 PM

Quote:

Originally Posted by ferrari (Post 5887447)
Again, which PDF viewing application is involved here?

Hi Ferrari ,
to view the PDF I download locally because the raspberry doesn't have a graphical interface, and I use Xreader; to print it I use the standard lp command ( in the script is the line LP_OUTPUT=$(lp $LP_OPTIONS "$f") ) the same as for postscript and plain text.

Gian Carlo

ferrari 08-05-2018 05:58 PM

Quote:

...to print it I use the standard lp command ( in the script is the line LP_OUTPUT=$(lp $LP_OPTIONS "$f") ) the same as for postscript and plain text.
Ok, thanks for the clarification. I think a bug report will be required to resolve your landscape printing issue.

Shadow_7 08-05-2018 08:57 PM

My printer requires extra steps in debian. It needs the pnm2ppa part. Plus others:

printer-driver-hpcups
printer-driver-pnm2ppa
printer-driver-postscript-hp
hplip
hplip-data
cups-bsd

some of which are not installed by default. For the remote clients I need to be in the lp and lpadmin groups plus an entry for the hostname in /etc/hosts on the clients (statically configured IPs). And other admin steps.

# lpstat -a
# lpoptions -d HP_DESKJET_720C_rpi3bplus

To make it the default printer. Most times when it doesn't work, I forgot to plug the usb to parallel port adapter in. Or I disabled cups, cups-browsed, or exim4 from running on both ends. Cups does job management via email / exim4. When none of the above works, a reboot with the printer plugged in and turned on solves most woes. But I'm a bit of a minimalist and stop various things from running to save CPU, RAM, thermals and such with a shorter than default ps output. When none of that works finding the correct .ppd and putting it with all the other ppd's helps.


All times are GMT -5. The time now is 01:43 AM.