• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to convert txt file to postscript ??

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic