Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert txt file to postscript ??  RSS feed

Madhu Kaparapu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to convert txt file to postscript file
I have tried with following code but "No suitable factories" are available it displays. Can any one help me how to convert txt file to postscript using
javax.print api or any other api

public class PrintTexttoSream {

public static void main(String args[]) {

/* Use the pre-defined flavor for a Text from an InputStream */
DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;

/* Specify the type of the output stream */
String psMimeType = DocFlavor.INPUT_STREAM.POSTSCRIPT.getMimeType();

/* Locate factory which can export a text stream as Postscript */
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);

if (factories.length == 0) {
System.err.println("No suitable factories");

try {
/* Load the file */
FileInputStream fis = new FileInputStream("E:\\temp\\ReadMe.txt");
/* Create a file for the exported postscript */
String filename = "E:\\temp\\";
FileOutputStream fos = new FileOutputStream(filename);

/* Create a Stream printer for Postscript */

StreamPrintService sps = factories[0].getPrintService(fos);

/* Create and call a Print Job for the Text */
DocPrintJob pj = sps.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(2));

Doc doc = new SimpleDoc(fis, flavor, null);

pj.print(doc, aset);
System.out.println("Successfully converted to postscript");

} catch (PrintException pe) {
} catch (IOException ie) {
Ulf Dittmer
Posts: 42972
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like GNU enscript might help. A Windows version seems to be available here.
[ January 09, 2006: Message edited by: Ulf Dittmer ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!