Printing to Hard-Printer in java with 300dpi

前端 未结 1 2024
名媛妹妹
名媛妹妹 2021-01-27 02:43

Okay, so i just started working on a program that is supossed to print out its graphics. Mine is almost identical to the copyrighted one at Oracle located here http://docs.oracl

相关标签:
1条回答
  • 2021-01-27 03:11

    You need to make use of the Print Services API. This allows you to request certain properties for a PrintJob, including the DPI.

    This is a RELLAY basic example...

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
    aset.add(new MediaPrintableArea(2, 2, 210 - 4, 297 - 4, MediaPrintableArea.MM));
    
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPrintable(new PrintTask());
    
    if (pj.printDialog(aset)) {
        try {
            pj.print(aset);
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
    

    Take a look at Working with Print Services and Attribues for more details

    0 讨论(0)
提交回复
热议问题