Can't set Printing Attributes for DocPrintJob Job

S

stat

Hi, everyone

i 've been trying to set some printing attributes for a .ps file using
PrintRequestAttributeSet class
but nothing happens.What i want to do is to set the tray on a network
printer(HP LaserJet 4100 Series PCL ). I am able to print fine but
can't set the tray through my prog.
Also notice that i don't want any user interaction(silent print), so
don't wanna use the printDialog().
Any ideas suggestions?

Thanx in advance..

public static void main(String[] args)
{
PrintService defaultPrintService =
PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printerJob = defaultPrintService.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

Doc simpleDoc = null;
String psFile = "F:/test.ps";
FileInputStream in = null;

try
{
in = new FileInputStream(psFile);
simpleDoc = new SimpleDoc(in, DocFlavor.INPUT_STREAM.AUTOSENSE,null);

aset.add(PrintQuality.HIGH);
aset.add(new Copies(2));
aset.add(MediaTray.MAIN);

//I would like to print from the buttom(<=>main) tray even when there
are papers in
//another e.g.manual feed,not to print from manual when paper is
present in manual feed

printerJob.print(simpleDoc,aset);

}
catch(Exception e){System.out.println(e.getMessage());}
}
 
M

Marian Schedenig

stat said:
i 've been trying to set some printing attributes for a .ps file using
PrintRequestAttributeSet class
but nothing happens.What i want to do is to set the tray on a network
printer(HP LaserJet 4100 Series PCL ). I am able to print fine but
can't set the tray through my prog.
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.
 
S

stat

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top