M
Mika Suomi
I have tried to print a text file and I have read articles from java.sun -
pages and there is an example which tell you to use in flavor
TEXT_PLAIN_TEXT but when I try to compile it I got this message:
DocFlavor.INPUT_STREAM.TEXT_PLAIN_TEXT cannot be resolved
And I have tried to use other options but bad result no printing I put the
code I use in here maybe somebody could help me.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class PrintToPaper {
private FileInputStream texti;
public PrintToPaper()
{
}
public void Print(){
try{
text=new FileInputStream("G:\\Work\\Java\\TEST.txt");
}
catch(FileNotFoundException e){
}
if(text==null){
return;
}
DocFlavor myFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
Doc MyDoc = new SimpleDoc(text, myFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
aset.add(MediaSizeName.ISO_A4);
aset.add(Sides.ONE_SIDED);
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = pservice.createPrintJob();
try {
job.print(MyDoc,aset);
}
catch (PrintException e) {
System.err.println(e);
}
}
}
pages and there is an example which tell you to use in flavor
TEXT_PLAIN_TEXT but when I try to compile it I got this message:
DocFlavor.INPUT_STREAM.TEXT_PLAIN_TEXT cannot be resolved
And I have tried to use other options but bad result no printing I put the
code I use in here maybe somebody could help me.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class PrintToPaper {
private FileInputStream texti;
public PrintToPaper()
{
}
public void Print(){
try{
text=new FileInputStream("G:\\Work\\Java\\TEST.txt");
}
catch(FileNotFoundException e){
}
if(text==null){
return;
}
DocFlavor myFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
Doc MyDoc = new SimpleDoc(text, myFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
aset.add(MediaSizeName.ISO_A4);
aset.add(Sides.ONE_SIDED);
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = pservice.createPrintJob();
try {
job.print(MyDoc,aset);
}
catch (PrintException e) {
System.err.println(e);
}
}
}