3
votes

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
Duplexing might be non-standard (it often is). Since you are on Windows, can you try printing a duplex job (eg 2 blank pages) to the printer, and see if they come out as a single sheet of paper ? If that works then you can print the same job to a file and look inside the file to see what control sequences the Windows driver is embedding for this. Oh wait....KenS
Duplexing often gets reset when you terminate a job, and any trailing page gets flushed. My guess would be that there is more than one document close in the file. Can you share an example ? Preferably 2 blank pages, but I guess one word per page would be OK.KenS
Did you ever figure this out? We are trying to do something similar and ran in to the same problems you areJohn
No not really, the project got put to one side and I haven't had chance to go back to it. Sorry.Martyn
@Martyn: What line endings are you using in your PJL header? I've found that some printers choke if you aren't consistent with line endings. The PJL "standard" only requires <LF> but some printers may require both <CR> and <LF>, and mixing and matching can also sometimes mess things up.dreamlax

2 Answers

3
votes

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.

1
votes

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 :)