コード例 #1
0
  public void handlePrintButtonAction(ActionEvent actionEvent) {
    //        try{
    //            Printer printer = Printer.getDefaultPrinter();
    //            PageLayout pageLayout = printer.createPageLayout(Paper.A4,
    // PageOrientation.PORTRAIT, Printer.MarginType.DEFAULT);
    //            NodePrinter nodePrinter = new NodePrinter();
    //            Rectangle printRectangle = new Rectangle(printForm.getLayoutX(),
    // printForm.getLayoutY(), printForm.getWidth(), printForm.getHeight());
    //            PrinterJob printerJob = PrinterJob.createPrinterJob();
    //
    //            nodePrinter.setScale(1);
    //            nodePrinter.setPrintRectangle(printRectangle);
    //            if(nodePrinter.print(printerJob, false, printForm, pageLayout)){
    //                printerJob.endJob();
    //            }
    //        }catch (Exception ex){
    //            Globals.LOGGER.log(Level.WARNING, ex.getMessage());
    //        }

    try {
      Printer printer = Printer.getDefaultPrinter();
      PageLayout pageLayout =
          printer.createPageLayout(
              Paper.A5, PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);
      PrinterJob printerJob = PrinterJob.createPrinterJob();

      if (printerJob.printPage(pageLayout, printForm)) {
        printerJob.endJob();
      }
    } catch (Exception ex) {
      Globals.LOGGER.log(Level.WARNING, ex.getMessage());
    }
  }
コード例 #2
0
 PageLayout defaultPageLayout() {
   if (defaultLayout == null) {
     Paper paper = defaultPaper();
     PageOrientation orient = defaultOrientation();
     defaultLayout = fxPrinter.createPageLayout(paper, orient, MarginType.DEFAULT);
   }
   return defaultLayout;
 }