Hi,
this is a piece of code I use to print out an image from a file:
//you should have these imports when using printing stuff, for the others figure out yourself
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
try {
InputStream is = new BufferedInputStream(new
FileInputStream(sourceFile));
// Find the default service
DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
aset.add(Chromaticity.COLOR);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
// Monitor print job events; for the implementation of PrintJobWatcher,
// see e702 Determining When a Print Job Has Finished
PrintJobWatcher pjDone = new PrintJobWatcher(job)
// Print it
job.print(doc, aset);
// Wait for the print job to be done
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
}
catch (PrintException ex) {
JOptionPane.showMessageDialog(null, ex, "PrintException!", 0);
}
catch (IOException ex) {
JOptionPane.showMessageDialog(null, ex, "PrintException (IOException)!", 0);
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex, "PrintException (Exception)!", 0);
}