Printing

Other topics

Basic printing

PrinterJob pJ = PrinterJob.createPrinterJob();

if (pJ != null) {
    boolean success = pJ.printPage(some-node);
    if (success) {
        pJ.endJob();
    }
}

This prints to the default printer without showing any dialog to the user. To use a printer other than the default you can use the PrinterJob#createPrinterJob(Printer) to set the current printer. You can use this to view all printers on your system:

System.out.println(Printer.getAllPrinters());

Printing with system dialog

PrinterJob pJ = PrinterJob.createPrinterJob();

if (pJ != null) {
    boolean success = pJ.showPrintDialog(primaryStage);// this is the important line
    if (success) {
        pJ.endJob();
    }
}

Contributors

Topic Id: 5157

Example Ids: 696,697

This site is not affiliated with any of the contributors.