1

How can I print duplex in java!?

Here's my code, but it didn't work - it only works in microsoft word (so the printer can do it)

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(2));
    pras.add(Sides.DUPLEX);

PrinterJob pj = PrinterJob.getPrinterJob();
    PageFormat pf = pj.defaultPage();
    Paper temp = pf.getPaper();

    temp.setImageableArea(1, 3, temp.getWidth(), temp.getHeight());
    pf.setPaper(temp);

    if (pj.printDialog(pras)) {
        try {
            pj.setPrintable(this, pf);
            pj.print(pras); //  Drucken
            return true;
        } catch (Exception PrintException) {
            .....
        }

I tried to give only the attributes to print, only to the dialog, etc. etc. etc. It print's the document 2 times, but not duplex! (also tried Sides.TWO_SIDED_LONG_EDGE..)

Christian 'fuzi' Orgler
  • 1,682
  • 8
  • 27
  • 51
  • Does the answer to http://stackoverflow.com/questions/5775740/java-print-program-with-specfications-issues help you? – Francis Upton IV Jul 13 '12 at 09:58
  • not really.. because I print it with graphics, not with a document - and I tried it also to give the attributeset (like in code) to the print method or/and the printDialog... even when I set it up on the printDialog on my own it doesn't print duplex :/ – Christian 'fuzi' Orgler Jul 13 '12 at 10:15
  • Bummer, my only other suggestion is to google around for the model of the printer you are using and see if there is something odd about Java's interaction with that. – Francis Upton IV Jul 13 '12 at 10:16
  • I'd recommend checking out the following for a more thorough treatment of the issue: [Printing with Attributes(Tray Control, Duplex, etc...) using javax.print library](http://stackoverflow.com/questions/14328012/printing-with-attributestray-control-duplex-etc-using-javax-print-library) – amaidment Sep 30 '15 at 07:48

1 Answers1

1

The Problem was my printer,... it always turn the option for duplex to be disabled.

Christian 'fuzi' Orgler
  • 1,682
  • 8
  • 27
  • 51