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);
}
}
}