I have RTF file on the sever I want directly take the printout of the file using a JAVA Program. I tried the following code (Consider only one printer(LIPI) is connected to server)
FileInputStream psStream = null;
try {
psStream = new FileInputStream("C://SampleBoard2.rtf");
} catch (FileNotFoundException ffne) {
ffne.printStackTrace();
}
if (psStream == null) {
return;
}
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
PrintService myPrinter = null;
for (int i = 0; i < services.length; i++){
String svcName = services[i].toString();
myPrinter = services[i];
}
if (myPrinter != null) {
DocPrintJob job = myPrinter.createPrintJob();
try {
job.print(myDoc, aset);
} catch (Exception pe) {pe.printStackTrace();}
} else {
System.out.println("no printer services found");
}
The file gets spooled to the printer and print also starts, but the printer prints the contents of thge RTF file like a text file contents. What should be done to render the file to RTF and then print?
I get something like this in the print.
\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\froman\fcharset0 Courier;}{\f2\froman\fcharset0 Arial;}{\f3\froman\fcharset0 unknown;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}{\stylesheet {\style\s0 \ql\fi0\li0\ri0\f2\fs24\cf0 Normal;}{\style\s3 \ql\fi0\li0\ri0\f2\fs26\b\cf0 heading 3;}{\style\s2 \ql\fi0\li0\ri0\f2\fs28\b\i\cf0 heading 2;}{\style\s1 \ql\fi0\li0\ri0\f2\fs32\b\cf0 heading 1;}} ..... .... ...
.... ... ...
Where am I going wrong?
RTF rendering engineforJAVAand where can I get one and how to place it between the printer and the class... - Sangeet Menon