> i 've been trying to set some printing attributes for a .ps file using
> PrintRequestAttributeSet class
[quoted text clipped - 3 lines]
> Also notice that i don't want any user interaction(silent print), so
> don't wanna use the printDialog().
Allow me to revive this old thread. I have a similar problem: 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);
}
Thanks,
Marian.
stat - 16 Nov 2006 06:37 GMT
I think i've finally found a solution to this problem.
It consists of the following streps:
1)If your printer's PERSONALITY supprots PDF then you can print the pdf
files
directly from java using flavor AUTOSENSE not PDF.The problem is that
you can't,
or at least i couldn't set the printing attributes with
AttributeSet.add(...)
2)If you want to pass attributes(Input tray,stappling,duplex...)you
must:
a)Convert the pdf to ps; using ghostscript or any pdf->ps converter
b)INSERT the appropriate POSTSCRIPT commands in the ps file;
this can be done by e.g reading through the entire file untill
u find some specific
word(%%Trailer or %%EOF or %%Page...) and inserting the ps
commands
c)Print the ps file using PrintJob with flavor always AUTOSENSE.
Well, that has worked for me but it takes a while for the conversion
and reading of the files...
however it works.
If someone has a better non-commercial way plz let me know.