Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8123023

PrintJob.printPage(layout, node) uses printer's layout settings rather than the passed in layout

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • javafx
    • Mac OS X 10.8.5, MacBook Pro 15" Retina, jdk 1.8.0 b109

      The following code prints the node in portrait mode with US Letter pagesize rather than using the settings of the manually created pageLayout instance. The only way to get it to print in the wanted A4/Landscape layout is to select those settings manually in the Page Setup dialog.

      try {
      Printer printer = Printer.getDefaultPrinter();
      PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
      AnchorPane node = FXMLLoader.load(getClass().getResource("report.fxml"));
      double scaleX = pageLayout.getPrintableWidth() / 1468.0;
      double scaleY = pageLayout.getPrintableHeight() / 974.0;
      node.getTransforms().add(new Scale(scaleX, scaleY));
      PrinterJob job = PrinterJob.createPrinterJob(printer);
      if (job != null) {
      job.showPageSetupDialog(null);
      job.showPrintDialog(null);
      boolean success = job.printPage(pageLayout, node);
      if (success) {
      job.endJob();
      }
      }
      } catch (Exception ex) {
      ex.printStackTrace();
      }

            prr Philip Race
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: