Problems printing PostScript files with PJL commands using gsprint

10.1k views Asked by At

We have developed an in-house printing solution that allows users to manage their prints (audit/merge/review/send to multiple printers) etc... but we are having issues with the very end of the process - the final print.

Currently our solution stores documents (original & after merging) in PDFs. We need to be able to send these documents to a particular printer and have it in some cases (when the user has selected the option) print page 1 to tray 8 and the rest to tray 1. We can't split the PDFs and print them separately as they also have to be stapled by the printer as a single job.

Our idea was to convert the PDF files to PostScript files using ghostscript then insert PJL commands into the PostScript and then print this modified PostScript file using gsprint.

Unfortunately the combination of ghostscript, postscript, PJL and gsprint doesn't seem to be working. The PJL commands we try, which we CAN get to work within text files sent to the printer via the windows copy command, don't seem to have the same affect when put into the PostScript files and printed using gsprint.

Can anyone spot any hideous flaws in what we are doing to the PostScript or have any idea why the PostScript->PJL amends->gsprint workflow we have might not be working?

It's been very difficult to find examples online so it's very possible our placement of PJL commands is incorrect.

(//comments not in final file)

<ESC>%-12345X@PJL JOB<ESC>&l8H           //start job printing first page 
@PJL ENTER LANGUAGE = Postscript         //to tray 8 (letterhead)
@PJL COMMENT CANPJL SET STAPLE=ONEUPLEFT //indicate the document should be stapled
%!PS-Adobe-3.0                           //start of PostScript file proper
---
%%PageTrailer                            //end of first page
<ESC>%-12345X@PJL EOJ<ESC>%-12345X       //end the first job
%%Page: 2
<ESC>%-12345X@PJL JOB<ESC>&l7H           //start 2nd job to print remaining
---                                      //pages to tray 1 (plain)
---
%%EOF
<ESC>%-12345X@PJL EOJ<ESC>%-12345X       //end 2nd job

We then take this modified PostScript and use gsprint as follows:

gsprint -noquery -ghostscript gswin32c -printer "printer" "C:\postscriptfile.ps"

This all print out to the default tray and unstapled, i.e. none of this works as expected.

I hope it's clear what we are trying to achieve. Any help would be greatly appreciated.

Thanks in advance.

PS: All our printers are Canon printers.

Edit:

After KenS's answer below it seems the logical workflow should instead be PDF->PCL->add PJL->send to printer with "copy"

Unfortunately we are still having issues with this, certain PJL commands seem to be ignored by our printers (the printers are definitely PCL printers).

If we take a 2 page PDF produced by Microsoft Word, convert it to PCL using ghostscript then edit that PCL file with Notepad++ add add the following:

<ESC>%-12345X@PJL JOB NAME = "My Print Job Name"<CR><LF>
@PJL SET DUPLEX = ON
@PJL SET OUTBIN = LOWER
@PJL ENTER LANGUAGE = PCL
...original PCL data...
<ESC>%-12345X@PJL EOJ<CR><LF>
<ESC>%-12345X

the document comes out of the lower output tray but not duplexed. But what is extra odd is that the printer seems to take much longer to print when DUPLEX = ON than the exact same job with DUPLEX = OFF and it sounds like it's doing something different internally.

Any ideas?

2

There are 2 answers

0
Reddymails On

We had similar issue this is how we did using ghost script and PJL

http://reddymails.blogspot.com/2014/07/how-to-print-documents-using-java-how.html

Also bfo.com has some commercial jars which do the same thing without ghost script and in a Pure java way. But you have to pay for it :)

3
KenS On

I think you misunderstand how gsprint operates. It takes an input file, renders it to a bitmap, draws that bitmap on an appropriate canvas, and then uses the Windows printing system to print that canvas on a printer. It does not have any control of the printer at all, as a result embedding anything which is expected to control the printer (as opposed to the rendering) will not have any effect.

In addition, PJL is asociated with HP PCL printers, not with PostScript printers. Whil;e your PJL may work on a PCL printer, because it treats each page as a separate job, it won't work at all on a PostScript printer, and may well cause it to give you an error, depending on whether the interpreter ignores PJL commands or not.

In order to control the printer, you will need to determine what kind of input the printer supports (PostScript or PCL), you then need to convert your PDF to that form, then insert appropriate control sequences. In the case of a PCL printer you might reasonably use PJL, for PostScript printers you should control this using the setpagdevice operator. Assuming you have a Windows .WPD or .PPD file for your printer, the relevant control sequences can be found there, or by printing a few test files and examining their contents.

In passing; you say that the commands you are using work when sending text files to the printer. This means the printer at least understands PJL and is almost certainly a PCL printer. You can't send text to a PostScript printer, it will generate an error, because PostScript is a programming language and you will have syntax errors with any random piece of text. You can however send text to a PCL printer which assumes that anything not starting with a 0x1B (escape) is just text to be printed.

So using Ghostscript to produce PCL output, inserting your PJL as you have above, and then sending the result directly to the printer should probably work. Of course identifying the end of each page might be more difficult in a PCL file.