Printing API and Attributes
Hi!
Forgive me for posting this twice; I originally sent it as a reply to an
older (unresolved) thread, but perhaps that was a bad idea and I do have
a chance to get answers in a new thread.
I can print .ps files with no problems on my windows box at work, but
the printer completely ignores all attributes I specify.
The printer is a HP LaserJet 1320 PS. It correctly gives me a list of
media trays. But regardless of which tray I select, or what orientation
or number of copies, I always get exactly one printout in portrait mode
from the standard tray. Now the printer really has only one tray plus a
manual feed, but I figure even if all other reported trays are
redirected to the standard tray by the driver, at least the manual feed
should work separately - and if not that, I'd still expect it to handle
at least the Copies attribute correctly.
On my Linux box at home my test program doesn't even list any printers,
but perhaps that's because it doesn't see my CUPS server address
configured through KDE; I'll have to try the test prog directly on the
server.
Here's the code I use for printing:
public void print(PrintService ps, MediaTray mt, int copies, boolean
landscape, InputStream in) throws PrintException
{
DocPrintJob pj = ps.createPrintJob();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(in, flavor, null);
PrintRequestAttributeSet attributes = new
HashPrintRequestAttributeSet();
if (mt != null)
{
attributes.add(mt);
}
attributes.add(new Copies(copies));
if(landscape)
{
attributes.add(OrientationRequested.LANDSCAPE);
}
else
{
attributes.add(OrientationRequested.PORTRAIT);
}
pj.print(doc, attributes);
}
I've been scouting the net for days, but I can't find any concrete
information on this (it seems people had unresolved problems with
printing until Java 5, and since then hardly anyone has posted news
about it).
Thanks,
Marian.