import java.io.FileInputStream;
import java.io.FileNotFoundExcetion;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.Sides;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.javax.print.PrintServiceLookup;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.SimpleDoc;
...
FileInputStream psStream;
try
{
psStream = new FileInputStream( "file.ps" );
}
catch ( FileNotFoundException e )
{
return;
}
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;
Doc myDoc = new SimpleDoc( psStream, psInFormat, null );
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add( new Copies(5) );
aset.add( MediaSize.A4 );
aset.add( Sides.DUPLEX );
PrintService[] services = PrintServiceLookup.lookupPrintServices( psInFormat, aset );
if ( services.length > 0 )
{
DocPrintJob job = services[0].createPrintJob();
try
{
job.print( myDoc, aset );
}
catch ( PrintException e )
{
}
}