docs: protected void doPrint() {
  
          PrintablePage pageInView = previewPane.getPrintablePage();
          PrintablePage pageToPrint = new PrintablePage();
  
          try {
              pageInView.bindPage(pageToPrint);
  
              Printer printer = Printer.getDefaultPrinter();
  
              if (printer == null || settingsView.getPaperView()
                      .getAvailablePapers().isEmpty()) {
                  // Show an Error
                  Alert alert = new Alert(AlertType.INFORMATION);
                  alert.initOwner(dialog);
                  alert.setTitle(Messages
                          .getString("DateControl.TITLE_CALENDAR_PROBLEM"));
                  alert.setHeaderText(
                          Messages.getString("PrintView.NO_PRINTERS"));
                  alert.setContentText(
                          Messages.getString("PrintView.ERROR_NO_PRINTER"));
                  alert.show();
                  return;
              }
  
              hide();
              LoggingDomain.PRINTING.fine("printer = " + printer);
  
              PageLayout layout = null;
  
              final Paper paper = pageInView.getPaper();
              final PageOrientation pageOrientation = pageInView.getViewType()
                      .getPageOrientation();
              final PaperView.MarginType marginType = pageInView.getMarginType();
  
              LoggingDomain.PRINTING.fine("paper = " + paper);
              LoggingDomain.PRINTING.fine("pageOrientation = " + pageOrientation);
              LoggingDomain.PRINTING.fine("marginType = " + marginType);
              LoggingDomain.PRINTING
                      .fine("custom margins = left: " + pageInView.getLeftMargin()
                              + ", right: " + pageInView.getRightMargin()
                              + ", top: " + pageInView.getTopMargin()
                              + ", bottom: " + pageInView.getBottomMargin());
  
              switch (marginType) {
              case DEFAULT:
                  layout = printer.createPageLayout(paper, pageOrientation,
                          Printer.MarginType.DEFAULT);
                  break;
              case MINIMUM:
                  layout = printer.createPageLayout(paper, pageOrientation,
                          Printer.MarginType.HARDWARE_MINIMUM);
                  break;
              case CUSTOM:
                  layout = printer.createPageLayout(paper, pageOrientation,
                          pageInView.getLeftMargin(), pageInView.getRightMargin(),
                          pageInView.getTopMargin(),
                          pageInView.getBottomMargin());
                  break;
              }
  
              // sizes of print page and physical page
              double pageWidth = pageToPrint.prefWidth(-1);
              double pageHeight = pageToPrint.prefHeight(-1);
  
              double printableWidth = layout.getPrintableWidth();
              double printableHeight = layout.getPrintableHeight();
  
              // scaling
              double scaleX = printableWidth / pageWidth;
              double scaleY = printableHeight / pageHeight;
              double scale = Math.min(scaleX, scaleY);
  
              LoggingDomain.PRINTING.fine("pageWidth / pageHeight = " + pageWidth
                      + " / " + pageHeight);
              LoggingDomain.PRINTING.fine("printableWidth / printableHeight = "
                      + printableWidth + " / " + printableHeight);
              LoggingDomain.PRINTING
                      .fine("scaleX / scaleY = " + scaleX + " / " + scaleY);
              LoggingDomain.PRINTING.fine("scale = " + scale);
  
              pageToPrint.applyCss();
              pageToPrint.layout();
              pageToPrint.getTransforms().add(new Scale(scale, scale));
  
              // transformation = center
              final double translateX = (printableWidth - (pageWidth * scale))
                      / 2;
              final double translateY = (printableHeight - (pageHeight * scale))
                      / 2;
  
              LoggingDomain.PRINTING.fine("translateX / translateY = "
                      + translateX + " / " + translateY);
  
              pageToPrint.setTranslateX(translateX);
              pageToPrint.setTranslateY(translateY);
  
              PrinterJob job = PrinterJob.createPrinterJob(printer);
              JobSettings settings = job.getJobSettings();
              settings.setJobName(Messages.getString("PrintView.TITLE_LABEL"));
              settings.setPageLayout(layout);
  
              if (job.showPrintDialog(getScene().getWindow())) {
                  do {
                      boolean success = job.printPage(pageToPrint);
                      if (!success) {
                          break;
                      }
                  } while (pageToPrint.next());
  
                  job.endJob();
              }
          } finally {
              pageInView.unbindPage(pageToPrint);
          }
      }