My PIPE printing scripts
Purpose
Rather than having all jobs be appended to a ever growing text file assigned to each printer device, to create a unique output file for each job, as both text and PDF.
History
For quite a while now it has been posible to configure a printer to write
to a unix PIPE so the printout can be handled by a backend script. I have used
that for a long time now to generate simple text output files for guest
batch jobs on my website.
That is the main printer interface script.
I decided it would be nice to have properly formatted output (form feeds enforced,
correct character spacing etc) which wasn't really possible from the text file.
So I opened the PDF syntax manual and eventually figured out how to convert the text files
to PDF files. And as I was leaving the form feed codes in the text files
anyway it was easy to use those to generate the correct page breaks required.
So what you have here now is the origional printer interface script, with a few lines added
to call a new script that will convert the text file to a PDF file. Plus the converter
script of course as thats why you are reading this page.
One note. I reconfigured JES2 so one printer (00E) was dedicated to print class G only and made that printer the pipe printer. You should look at doing something similar as you don't really want all output to be parsed by scripts.
Configuring Hercules to print to a pipe
Thats fully covered on the hercules website of course so refer there for details
on the configuration file syntax, but simply put using the below
line in the configuration file that I am using results in all output from printer
000E being piped into the script.
You will of course have to adjust the script path to where you decide to
place the script.
And of course you need to be using a unix host system to run hercules.
000E 1403 "|/home/mark/hercules/turnkey3/mark/scripts/printer_interface.sh" crlf
The printer_interface.sh script
As data is piped into the script it basically has to loop forever waiting for input. Thats no problem as it does end when hercules is stopped.
The only minor issue is that as it is a pipe there is no 'session drop/start' to indicate when one job
ends printing and the next begins; which means that the script uses job start
and job end text on the banner pages of each job to decide how to split jobs.
So in the oputput files produced the start banner page doesn't start until a start job text
is found and the end banner page is truncated when the end job text is found.
The job output pages themselves are fine so I'm not going to worry about the above.
The script design is simply to keep reading input forever, switching output files
when it detects a job start of job end block on the banner page.
It does differentiate between JOB and STC tasks as I put those into seperate
directories; you may decide to change that if you wish.
This is a bash script, it won't work under any other shell.
The PDF generation has been added to the script by simply adding a few lines
to call the PDF generating script into it.
That is what I required as I still wanted to keep the text file output
as an option for guest users on my site; they shouldn't need to have to start
a PDf viewer when debugging their jobs :-).
Oh, the script itself. Well if you have read this far... the printer_interface.sh script is here as a text file which you can save and rename as suits you.
You will have to change the paths, and you may not want to keep STC and JOB output in seperate
directories, but the entire idea is you customise it to your personal needs anyway.
And you do not need the 'sudo' steps as they are after the files have been generated.
They are in there as part of my post processing of a job file is to copy it to me web
server directories which you don't need to do. But as any bug fixes I make will simply
have a new copy of what I use copied over here each time you will have to take those bits out
of the script yourself.
The makepdf script, what you really wanted
You probably all have your own pipe scripts, but converting text files to PDF files...
If you have looked at the script above you will have seen how simple it is, just call my makepdf
script.
Why a script rather than a program you ask ?. Why write a program that may not be portable when unix bash scripting is. Speed is not an issue here, we are just spooling output. And quite honestly I would rather use sed in a script to make global changes to object id tags (parent objects cannot be given child ids before the children have been created, the children cannot be given a parent id before the parent has been created, there is so much reworking of the output file going on doing it in C would be a nightmare). OK, I'm lazy. Scripting is easier.
So whats in the script. The way it is setup currently is to allow 132 characters per row,
and 72 rows per page; because I can't remember if lineflow has 72 or 66 lines per page so
I went with 72. It will need landscape printing.
If you are only interested in the script as a generic text to PDF tool you might want
to look at the comments arounf the PORTRAIT/LANDSCAPE keywords.
It has limitations in that I am not implementing page trees, I am hanging all pages off one Page parent. There probably is a limit of the number of pages that can be hung off a parent before page trees are needed, I haven't reached it yet and if I do it's probably time to switch to C rather than a bash script; so a later worry.
It has benefits, to hercules users anyway. It has been specifically coded to check
for the form feed character hercules puts into the printer data stream, and will
handle that anooying ocurrence of it ocurring in the middle of a line instead of
at the start of a line.
So for hercules users your PDF output will be as if it was printed on lineflow,
apart from the banner truncation noted as a limitation of the printer_interface.sh script.
For non hercules users there is a block of code you can remove :-) but it
won't do any harm to lave it in.
Basically... you have a text file
You 'makepdf textfile pdffile' and your textfile is a PDF file. BUT
The makepdf script was coded for known max line lengths of 132 characters in landscape mode.
I have run it in portrait mode with helvetica (as per the commented out blocks) and it works
fine, but if you want to use it for generic text files you might want to look at
putting in checks for line lengths and breaking lines up.
Am example of breaking lines in two is where the script detects a printer form feed
in the middle of a line so you could base your needs on that.
But for hercules users intending to use this script to PDF their job output, this works
just perfectly as supplied.
Oh, the script itself. Well if you have read this far... the makepdf script is here as a text file. However the control character for formfeed is stripped out when displayed as a web page so you should download both files in binary from the tar file below.
Combined files
And the files that will actually work are here.