I've been trying to determine whether a printer is capable of printing a Postscript (.ps) file. Using the following method, I've attempted to determine whether a printer can print the Postscript with the following code:
private void findPrinters( DocFlavor flav ) {
PrintService[] services = PrintServiceLookup.lookupPrintServices( flav, null );
System.out.println( flav );
if ( services != null && services.length != 0 ) {
System.out.println( "SUPPORTED:" );
for ( PrintService service : services ) {
System.out.println( service );
}
} else {
System.out.println( "NOT SUPPORTED" );
}
}
I've passed it DocFlavor.INPUT_STREAM.POSTSCRIPT
or DocFlavor.BYTE_ARRAY.POSTSCRIPT
and it would return Win32 Printer : HP LaserJet 2300L PS
and Win32 Printer : CutePDF Writer
(both of which are "virtual" printers - the former used to created PDF and the latter used to create Postscript). After installing "HP Universal Print Driver for Windows PostScript", Win32 Printer : HP Universal Printing PS
shows up as Postscript capable. However, I'm not certain if this driver is being used or not therefore I interpret this to be that none of the other attached printers can print a Postscript file.
Then I tried to feed a Postscript file to a couple of attached printers with the following sample code:
FileInputStream in = null;
PrintService prnSvc = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printJob = prnSvc.createPrintJob();
Doc doc;
in = new FileInputStream( "some.ps" );
if ( prnSvc.isDocFlavorSupported( DocFlavor.INPUT_STREAM.POSTSCRIPT ) ) {
/* USE THIS FOR A PS-capable printer */
doc = new SimpleDoc( in, DocFlavor.INPUT_STREAM.POSTSCRIPT, null );
} else {
/* USE THIS FOR OTHER PRINTER */
doc = new SimpleDoc( in, DocFlavor.INPUT_STREAM.AUTOSENSE, null );
}
printJob.print( doc, null );
It would print correctly on the Postscript capable printers as well as one of the network printers (a HP LaserJet P4014N) that Java says doesn't have Postscript support. On my receipt printer, it would print the Postscript file as if it were just text. It has been suggested to me that the network printer isn't responding correctly to Java (generic drivers, etc.) and that it could actually support Postscript. I've looked at documentation but couldn't determine whether LaserJet P4014N supports Postscript or not. I did find another printer (HP Laserjet 2055dn) and connected via USB to my computer and Java still reports that it doesn't support Postscript despite being able to print it with the above method.
Maybe I'm doing something wrong? If not, how do I correctly detect whether a printer supports Postscript? My ultimate goal is to determine whether a printer has Postscript support or not, if it doesn't convert the Postscript to JPG (loss in resolution, but the source does have images) and print that. If you have any suggestions for printing a Postscript file to a non-Postscript-capable printer, I'd love to hear it! Please let me know if you need additional information.
I found some sample Postscript files here that you could use.