A Java program that uses jPDFPrint to convert a PDF file to Postscript. The program queries the JVM for any print services that support Postscript output. At least one such services is always available in a Sun JVM. It then prints the PDF document, using jPDFPrint, to that print service, which will ouptut a Postcript file.

ocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);
 
System.out.println ("Available PS services: " + factories.length);
 
if(factories.length == 0)
{
   System.err.println ("No PS factories available!");
   System.exit(0);
}
 
// Open the PDF file
PDFPrint pdfPrint = new PDFPrint ("test.pdf", null);
 
// Open the output file
FileOutputStream fos = new FileOutputStream("output.ps");
 
// Use the first service available
StreamPrintService sps = factories[0].getPrintService(fos);
DocPrintJob pj = sps.createPrintJob();
 
// Define paper size
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
 
// Create simple doc using PDFPrint as Printable and print it
SimpleDoc doc = new SimpleDoc(pdfPrint, flavor, null);
pj.print(doc, aset);
 
// Close the output PS stream
fos.close();

Click here to view the Full Java source code.