Automatically printing out PCL Data

Discussion about the various options for output of the data captured by the Retro-Printer Module
Post Reply
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Automatically printing out PCL Data

Post by RWAP »

We have started some instructions on how to print the captured PCL data.

This uses the GhostPDL program by https://artifex.com/ - users can download and install the freeware version of this program onto the Raspberry Pi, but unfortunately, we have not been able to get it to print PCL data files downloaded from the internet without GhostPDL reporting an error.

The installation instructions are fairly straightforward (we welcome comments on how to improve this):

Code: Select all

Ensure cups libraries installed
apt-get install libcups2-dev libcupsimage2-dev

Download GhostPCL:

cd /tmp
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs921/ghostpdl-9.21.tar.gz
tar zxvf ghostpdl-9.21.tar.gz  
cd ghostpdl-9.21
./autogen.sh
./configure
make
make install

apt_get install -y inotify-tools
cd /home/pi/
Create a printpcl.sh file:

#! /bin/bash

inotifywait -m -e close_write /home/pi/data/pcl --format "%w%f" | \
while read filename; do gs -sDEVICE=printer -dNOPAUSE "$filename" -c quit; rm "$filename"; done  

Change rc.local to run this script
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

Oops - as we are printing out pcl data, we need to use a different program provided as part of the GhostPDL download (now why is that not clear anywhere)..

So the instructions become:

Code: Select all

Ensure cups libraries installed
apt-get install libcups2-dev libcupsimage2-dev

Download GhostPCL:

cd /tmp
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs921/ghostpdl-9.21.tar.gz
tar zxvf ghostpdl-9.21.tar.gz  
cd ghostpdl-9.21
./autogen.sh
./configure
make
make install

apt_get install -y inotify-tools
cd /home/pi/
Create a printpcl.sh file:

#! /bin/bash

inotifywait -m -e close_write /home/pi/data/pcl --format "%w%f" --exclude ".*\-output" | \
while read filename; do gpcl6 -sDEVICE=cups -sOutputFile="$filename-output" -dNOPAUSE "$filename"; rm "$filename"; lpr "$filename-output"; rm "$filename-output"; done  

Change rc.local to run this script
I am still not quite sure whether this will work (as I cannot actually get CUPS to even print a test page to my printer) however - there has to be a better way!
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

There is an error in printpcl.sh - it should read:

Code: Select all

inotifywait -m -e close_write /home/pi/data/pcl --format "%w%f" | \
while read filename; do gs -sDEVICE=printer -dNOPAUSE "$filename" -c quit; rm "$filename"; done  

inotifywait -m --exclude "pdf$" close_write /home/pi/data/pdf --format "%w%f" | \
while read filename; do gpcl6 -dPDFA=1 -dBATCH -dNOPAUSE -sColorConversionStrategy=/RGB -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" "$filename"; rm "$filename"; done 
The error was in the second inotifywait which read

Code: Select all

inotifywait -m -e --exclude "pdf$" close_write /home/pi/data/pdf --format "%w%f" | \
This will be fixed in v3.3 of the software image
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

I have now tried v9.27 of GhostPCL - there is another change now required to printpcl.sh. It should read:

Code: Select all

#! /bin/bash

inotifywait -m -e close_write /home/pi/data/pcl --format "%w%f" | \
while read filename; do gs -sDEVICE=printer -dNOPAUSE "$filename" -c quit; done

inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pdf --format "%w%f" | \
while read filename; do gpcl6 -dNOPAUSE -sColorConversionStrategy=/RGB -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" "$filename"; rm "$filename"; done
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

Further change to overcome a bug introduced somewhere along the line:

Code: Select all

#! /bin/bash

inotifywait -m -e close_write /home/pi/data/pcl --format "%w%f" | \
while read filename; do gs -sDEVICE=printer -dNOPAUSE "$filename" -c quit; rm "$filename"; done  

inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pdf --format "%w%f" | \
while read filename; do gpcl6 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" -sColorConversionStrategy=RGB "$filename"; rm "$filename"; done  
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

We have now decideed to stop using Ghostscript as we could not get it to always print to the default printer (answers on a postcard please....)

We have therefore amended printpcl.sh to read:

Code: Select all

#! /bin/bash

inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pdf --format "%w%f" | \
while read filename; do gpcl6 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" -sColorConversionStrategy=RGB "$filename"; rm "$filename"; done  

inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pcl --format "%w%f" | \
while read filename; do gpcl6 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" -sColorConversionStrategy=RGB "$filename"; lpr "${filename%.*}.pdf" ;rm "$filename"; rm "${filename%.*}.pdf"; done  
This uses a two stage approach now - it uses GhostPCL to convert the PCL in /home/pi/data/pcl to a PDF, prints the PDF using LPR command and then deletes the pcl and pdf files from that folder.
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: Automatically printing out PCL Data

Post by RWAP »

We have now found that the second inotify scrip doesn't always seem to fire, so the updated code puts both into functions:

Code: Select all

#!/bin/bash

monitor1() {
inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pdf --format "%w%f" |
while read filename; do gpcl6 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="/home/pi/data/pdf/$(date +'%Y-%m-%d_%H%M%S').pdf" -sColorConversionStrategy=RGB "$filename"; rm "$filename"; done
}

monitor2() {
inotifywait --exclude "pdf$" -m -e close_write /home/pi/data/pcl --format "%w%f" |
while read filename; do gpcl6 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="${filename%.*}.pdf" -sColorConversionStrategy=RGB "$filename"; lpr "${filename%.*}.pdf" ;rm "$filename"; rm "${filename%.*}.pdf"; done 
}

monitor1 &
monitor2 &
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
Post Reply