• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert txt file to postscript ??

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

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;
System.out.println(flavor.getMimeType());

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

/* 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");
System.exit(0);
}

try {
/* Load the file */
FileInputStream fis = new FileInputStream("E:\\temp\\ReadMe.txt");
/* Create a file for the exported postscript */
String filename = "E:\\temp\\ing1txt.ps";
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));
aset.add(MediaSizeName.ISO_A4);
aset.add(Sides.TWO_SIDED_LONG_EDGE);
aset.add(Finishings.STAPLE);

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

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

} catch (PrintException pe) {
System.err.println(pe);
} catch (IOException ie) {
System.err.println(ie);
}
}
}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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!