Can't set Printing Attributes for DocPrintJob Job

Discussion in 'Java' started by stat, Aug 25, 2006.

  1. stat

    stat Guest

    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());}
    }
     
    stat, Aug 25, 2006
    #1
    1. Advertising

  2. stat wrote:
    > 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.
     
    Marian Schedenig, Sep 27, 2006
    #2
    1. Advertising

  3. stat

    stat Guest

    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.
     
    stat, Nov 16, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. staff
    Replies:
    1
    Views:
    1,026
  2. Replies:
    0
    Views:
    704
  3. Julien Buratto

    [Job] Symbian C++ job

    Julien Buratto, Feb 3, 2004, in forum: C++
    Replies:
    2
    Views:
    601
    Julien Buratto
    Feb 3, 2004
  4. swordedotcom
    Replies:
    0
    Views:
    389
    swordedotcom
    Apr 23, 2006
  5. swordedotcom
    Replies:
    0
    Views:
    342
    swordedotcom
    Apr 23, 2006
Loading...

Share This Page