Skip to content

Instantly share code, notes, and snippets.

@F1lou
Last active August 7, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save F1lou/bc753e80fc07f5977c71e0f8ab3c4b2f to your computer and use it in GitHub Desktop.
Save F1lou/bc753e80fc07f5977c71e0f8ab3c4b2f to your computer and use it in GitHub Desktop.
PDFPrinter - Print via PDF to PDF-capable printer without CUPS
#!/bin/sh
if [ -n "$(find """/var/spool/PDFPrinter/$1""" -user $(whoami))" ]; then
if [ $(head -n 1 "/var/spool/PDFPrinter/$1" | grep PDF | wc -l) = 1 ]; then
RESULT=$( \
yad \
--display=:0.0 \
--center \
--title="Printing Options" \
--window-icon=printer \
--form \
--field=Number:NUM 1!1..100!1!0 \
--field=Twosided:CHK TRUE\
--field=Eco-Mode:CHK TRUE \
)
if [ $? = 0 ]; then
NUMBER=$(echo $RESULT | cut -f 1 -d '|')
DUPLEX=$(echo $RESULT | cut -f 2 -d '|')
ECO=$(echo $RESULT | cut -f 3 -d '|')
# -PJL-CONTROLCODE-----------------------------------
echo -e "\033%-12345X@PJL" > "/tmp/$1.pjl"
# -NUMBER--------------------------------------------
if [ $NUMBER -gt "1" ]; then
echo "@PJL SET COPIES=$NUMBER" >> "/tmp/$1.pjl"
fi
# -DUPLEX--------------------------------------------
if [ $DUPLEX = "TRUE" ]; then
echo "@PJL SET DUPLEX=ON" >> "/tmp/$1.pjl"
else
echo "@PJL SET DUPLEX=OFF" >> "/tmp/$1.pjl"
fi
# -ECO-MODE------------------------------------------
if [ $ECO = "TRUE" ]; then
echo "@PJL SET ECONOMODE=ON" >> "/tmp/$1.pjl"
else
echo "@PJL SET ECONOMODE=OFF" >> "/tmp/$1.pjl"
fi
# -PDFPrinterlanguage to PDF-------------------------
echo "@PJL ENTER LANGUAGE = PDF" >> "/tmp/$1.pjl"
# -CONTENT-------------------------------------------
cat "/var/spool/PDFPrinter/$1" >> "/tmp/$1.pjl"
# -FINISH--------------------------------------------
echo -e "\033%-12345X" >> "/tmp/$1.pjl"
cat "/tmp/$1.pjl" | nc <YOURPRINTERIP>:9100 # enter the Printer IP or network name without the < >
fi
rm -f "/tmp/$1.pjl" "/var/spool/PDFPrinter/$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment