Hello could you please help me with java printing? This is my code...
I used the Java API for printing. The problem is this code doesnt
find the print services. Any advice? thanks
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
public class PrintFoo
{
public static void main(String args[])
{
PrintFoo ps = new PrintFoo();
}
public PrintFoo()
{
try
{
FileInputStream textStream;
textStream=new FileInputStream("tobeprinted.txt");
if(textStream==null)
{
System.out.println("asdfsaf");
return;
}
DocFlavor flavor=DocFlavor.INPUT_STREAM.POSTSCRIPT;
Doc mydoc=new SimpleDoc(textStream,flavor,null);
PrintRequestAttributeSet aset=new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
PrintService[]services=PrintServiceLookup.lookupPrintServices(flavor,aset);
System.out.println(services.length);
if(services.length>0)
{
DocPrintJob job=services[0].createPrintJob();
try
{
job.print(mydoc,aset);
}
catch(PrintException pe)
{
System.err.println(pe);
}
}
}
catch(Exception ee)
{
System.err.println(ee);
}
}
}