I have a generated post script file and want to print using it. How can it be achieved in java either using javax print API or AWT. Is it possible?
Asked
Active
Viewed 3,470 times
1 Answers
2
Complicated. Does your printer(s) support PostScript? Is it networked? If so, most networked printers can talk LPR and you can shove the file over as-is. On Windows, you could also stream the file as-is to the lpt1:
mapped port via something like NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES
.
If you're on a server and you do lots of PostScript handling and your printer infrastructure supports it, I would very much look into the LPR protocol. I've written several LPR/LPD management functions in Java to handle printer jobs, so definetely know it can be done with some relative ease.

Jé Queue
- 10,359
- 13
- 53
- 61
-
Printer used: Canon iR5050 PCL6 – Rachel Oct 28 '10 at 20:37
-
Then you'll need to transform PS->PCL. I'd write a web service to perform the same. – Jé Queue Oct 28 '10 at 21:16
-
If i generate a PCL file instead of PS file so should i stream the PCL file to lpt1? – Rachel Oct 28 '10 at 21:27
-
Yes, PCL should be able to be streamed/copied over to said port without issue (or at least every other PCL printer with which I've worked). Ghostscript does a fantastic job of interpreting PostScript and transforming to other languages (e.g. PCL). If this is a commercial venture, remember there are a LOT of advantages to PostScript in terms of document management, and a lot of advantages to LPD for print queuing vs. direct byte copying. – Jé Queue Oct 28 '10 at 22:13
-
BTW, that printer should easily support PostScript, should not need to worry about PCL. – Jé Queue Oct 28 '10 at 22:18
-
Oh is it. I was not sure if Canon iR5050 PCL6 can support PS. Be it PCL or PS docflavor, i am unable to get the printer instance using the doc flavor niether as PCL or PS using the code below. What could be the issue. DocFlavor psFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT; PrintService[] services = PrintServiceLookup.lookupPrintServices(psFlavor, null); – Rachel Oct 28 '10 at 22:46
-
Could you please share a sample java code to print using a PS script. I tried hard to get it but in vain. – Rachel Oct 28 '10 at 22:49
-
Yep, http://www.canonir5050.com/ looks like `%!PS` magic is supported. The code I'm discussing using LPR is not über-difficult, but nor is it trivial. Contact me via my profile and I can share some additional info over email (it is commercial otherwise I'd post whatever snippets I could here). – Jé Queue Oct 29 '10 at 00:53
-
With Canon iR5050 PCL6, I tried to use the basic print feature of javax print. I was able to print contents from a txt file but i am unable to modify the no. of copies, orientation etc. even when setting the PrintRequestAttributes. Is it a printer specific issue? Is there any way to get around it? – Rachel Oct 29 '10 at 03:08
-
No. When i tried to fetch the supported docflavors of the printer using java print API, it does not specify PS or PCL. – Rachel Oct 29 '10 at 18:08
-
I'm talking about sending via FTP protocol, not the print API. – Jé Queue Oct 29 '10 at 18:23
-
If i FTP the PS to print the content, how do i specify the printer specific attributes like DUPLEX, LANDSCAPE etc. – Rachel Nov 03 '10 at 18:58