tray icon indicating copy to clipboard operation
tray copied to clipboard

QZ-Tray cannot manipulate duplex printing for PDF printing - only honors CUPS default setting - MacOS, Linux

Open lite1979 opened this issue 3 years ago • 7 comments

A client brought to our attention that if they try to print a two-page PDF using QZ-Tray with the config set to single page (not duplex), it still prints duplex.

This has been reproduced with QZ-Tray 2.1.3+1, MacOS Big Sur, and a Brother HL-L2380DW.

If the default setting in CUPS is set to Duplex, long side (portrait), then QZ-Tray will only print PDFs in portrait duplex, despite the config being for single page printing.

If the default setting in CUPS is set to Single Page, then QZ-Tray will only print PDFs on a single page, no duplex, despite config options.

Identical results were observed in Ubuntu 20.04

lite1979 avatar Jul 27 '21 20:07 lite1979

@Vzor- can you help write a small, reproducible code example so that we can file this with our JDK support provider?

tresf avatar Sep 27 '22 14:09 tresf

Two-page document for testing: two-pages.pdf

tresf avatar May 19 '23 15:05 tresf

Our JDK support provider has supplied us with the following code snippet for testing:

Usage:

javac JavaPrinting.java
java JavaPrinting ONE_SIDED two-pages.pdf
java JavaPrinting DUPLEX two-pages.pdf
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.SimpleDoc;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Sides;
import java.awt.print.PrinterJob;
import java.io.FileInputStream;
import java.io.InputStream;

public class JavaPrinting {

    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.err.println("usage: " + JavaPrinting.class.getName() + "java ONE_SIDED|TUMBLE|DUPLEX <path to pdf document>");
            System.exit(1);
        }

        String sidesAttr = args[0];
        String filename = args[1];
        System.out.printf("Input sides: %s%n", sidesAttr);
        System.out.printf("Input PDF document: %s%n", filename);

        try (FileInputStream psStream = new FileInputStream(filename)) {
            printWithAttributes(sidesAttr, psStream);
        }
    }

    private static void printWithAttributes(String sidesAttr, InputStream psStream) throws Exception {

        PrintService[] services = PrinterJob.lookupPrintServices();
        if (services == null || services.length == 0) {
            throw new RuntimeException("Print services not found!");
        }

        PrintService printService = services[0];
        System.out.printf("Found print service: %s%n", printService);

        Doc doc = new SimpleDoc(psStream, DocFlavor.INPUT_STREAM.PDF, new HashDocAttributeSet());

        PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
        attr.add(getSides(sidesAttr));

        for (Attribute attribute : attr.toArray()) {
            System.out.printf("Print request attribute: %s%n", attribute);
        }

        DocPrintJob printJob = printService.createPrintJob();
        printJob.print(doc, attr);
    }

    private static final Sides getSides(String sidesAttr) {
        switch (sidesAttr) {
            case "ONE_SIDED":
                return Sides.ONE_SIDED;
            case "TUMBLE":
                return Sides.TUMBLE;
            case "DUPLEX":
                return Sides.DUPLEX;
            default:
                throw new IllegalArgumentException("Unsupported side: " + sidesAttr + ", use ONE_SIDED, TUMBLE, or DUPLEX");
        }
    }
}

tresf avatar May 19 '23 15:05 tresf

So the plain java example works, so this is either something on our end, or the DocFlavor.INPUT_STREAM.PDF is a bad unit test.

tresf avatar May 19 '23 15:05 tresf

Oddly, HTML printing (JavaFX) defaults to two-sides as well.

tresf avatar May 19 '23 15:05 tresf

For Mac at least, this has been patched upstream, just awaiting a proper OpenJDK 11 release number that receives the patch.

https://bugs.openjdk.org/browse/JDK-8311033

tresf avatar Aug 09 '23 20:08 tresf

This will be backported to OpenJDK 11.0.21, 17.0.9.

tresf avatar Aug 29 '23 15:08 tresf