Hi,
I have an application that creates documentation in PDF format, but I need it in Postscript format (to do post processing on the documents) and send it to our printers with sockets (our printer only accepts PS documents through sockets), (I know I can use Ghostscript, but I prefer not using execute commands from within java), to fix this, I downloaded a Postscript driver from ADOBE and installed it, when I open the PDF and use File -> Print, and select Print to File option, it outputs the document in true PS format.
I then tried to do this programatically as my application will be generating 10 000 documents a day, and they need to be converted to PostScript, I used the javax.print.attribute.standard.Destination attribute when printing, but this seems to only create a copy of the file with a new extension and does not actually let the printer driver spool the document, so I am ending up with PDF documents with a PS extension. Am I doing something wrong, or is there a differant way of doing this?
I am included my source below (Please note that it is only a test app I wrote, so it is not nicely structured, as this is only for testing purposes):
import java.io.File;
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.attribute.standard.Destination;
import javax.print.attribute.standard.PrinterName;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
final String PRINTER_NAME = "Generic PostScript Printer";
final String IN_FILE = "C:/temp/InputDocument.pdf";
final String OUT_FILE = "C:/temp/OutputDocument.ps";
try{
PrintServiceAttributeSet list = new HashPrintServiceAttributeSet();
list.add(new PrinterName(PRINTER_NAME,null));
File outFile = new File(OUT_FILE);
if (outFile.exists()){
outFile.delete();
}
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintService[] ps = PrintServiceLookup.lookupPrintServices(flavor, list);
if (ps.length > 0){
PrintService psServices = ps[0];
FileInputStream file = new FileInputStream(IN_FILE);
DocPrintJob job = psServices.createPrintJob();
Doc doc = new SimpleDoc(file, flavor, null);
PrintRequestAttributeSet printSet = new HashPrintRequestAttributeSet();
printSet.add(new Destination(outFile.toURI()));
job.print(doc, printSet);
}
}catch(Exception e){
e.printStackTrace();
}
}
}
Please let me know if anything in my question is unclear.
Thank you in advance, any help would be greatly appreciated.
Edited by: AndreGroeneveldSA on Sep 3, 2010 12:42 PM