Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Can't set Printing Attributes for DocPrintJob Job

Thread view: 
stat - 25 Aug 2006 11:05 GMT
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());}
}
Marian Schedenig - 27 Sep 2006 14:35 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.