public void Print() {
    // If they didn't provide a mech exit
    if (Mechs.size() == 0) {
      return;
    }

    job.setJobName(jobName.trim());

    // Here is where we will show the print dialog, determine if it's a single mech or multiples
    if (useDialog) {
      if (Mechs.size() == 1) {
        if (!PrintDialog((PrintMech) Mechs.get(0))) return;
      } else {
        if (!BatchDialog()) return;
      }
    }

    // start building the print objects necessary
    GeneratePrints();

    job.setPageable(pages);
    boolean DoPrint = job.printDialog();
    if (DoPrint) {
      try {
        job.print();
      } catch (PrinterException e) {
        System.err.println(e.getMessage());
        System.out.println(e.getStackTrace());
      }

      Mechs.clear();
    }
  }
Пример #2
0
 public void pageableJob(Pageable pageable) throws PrintException {
   try {
     synchronized (this) {
       if (job != null) { // shouldn't happen
         throw new PrintException("already printing");
       } else {
         job = new sun.awt.windows.WPrinterJob();
       }
     }
     PrintService svc = getPrintService();
     job.setPrintService(svc);
     if (copies == 0) {
       Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
       copies = c.getValue();
     }
     job.setCopies(copies);
     job.setJobName(jobName);
     job.setPageable(pageable);
     job.print(reqAttrSet);
     notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
     return;
   } catch (PrinterException pe) {
     notifyEvent(PrintJobEvent.JOB_FAILED);
     throw new PrintException(pe);
   } finally {
     printReturned = true;
     notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
   }
 }
Пример #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (SHEET_COMMAND.equals(e.getActionCommand())) {
     new PreviewLoader((URI) sheetBox.getSelectedItem()).execute();
   } else if (PAGE_COMMAND.equals(e.getActionCommand())) {
     previewPanel.setPage(pageBox.getSelectedIndex());
   } else if (ZOOM_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     previewPanel.setScaleFactor(zoom);
   } else if (ZOOM_IN_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     zoomBox.setSelectedItem(zoom * ZOOM_MULTIPLIER);
   } else if (ZOOM_OUT_COMMAND.equals(e.getActionCommand())) {
     Double zoom = (Double) zoomBox.getSelectedItem();
     zoomBox.setSelectedItem(zoom / ZOOM_MULTIPLIER);
   } else if (PRINT_COMMAND.equals(e.getActionCommand())) {
     PrinterJob printerJob = PrinterJob.getPrinterJob();
     printerJob.setPageable(pageable);
     if (printerJob.printDialog()) {
       try {
         printerJob.print();
         dispose();
       } catch (PrinterException ex) {
         String message = "Could not print " + character.getNameRef().get();
         Logging.errorPrint(message, ex);
         frame.showErrorMessage(Constants.APPLICATION_NAME, message);
       }
     }
   } else if (CANCEL_COMMAND.equals(e.getActionCommand())) {
     dispose();
   }
 }
  public void PrintBattleforce() {
    if (battleforces.size() == 0) {
      return;
    }
    pages = new Book();
    page.setPaper(paper);

    if (jobName.isEmpty()) {
      jobName = "BattleForce";
    }
    if (battleforces.size() == 1) {
      BattleForce bf = ((BattleforcePrinter) battleforces.get(0)).getBattleforce();
      if (!bf.ForceName.isEmpty()) {
        jobName = bf.ForceName.trim();
      }
    }

    job.setJobName(jobName);

    if (useDialog) {
      for (int i = 0; i < battleforces.size(); i++) {
        BattleforcePrinter bf = (BattleforcePrinter) battleforces.get(i);
        dlgPrintBattleforce pForce =
            new dlgPrintBattleforce((javax.swing.JFrame) Parent, true, bf.getBattleforce());
        pForce.setLocationRelativeTo((javax.swing.JFrame) Parent);
        pForce.setVisible(true);
        if (!pForce.Result) {
          return;
        }

        bf.setType(pForce.Sheet);
      }
    }

    for (int i = 0; i < battleforces.size(); i++) {
      pages.append((BattleforcePrinter) battleforces.get(i), page);
    }

    job.setPageable(pages);
    boolean DoPrint = job.printDialog();
    if (DoPrint) {
      try {
        job.print();
      } catch (PrinterException e) {
        System.err.println(e.getMessage());
        System.out.println(e.getStackTrace());
      }
    }
  }
  // 从预览中点击打印按钮时执行此函数打印
  public void printBinaryPicture() {

    int formatIndex = jComboBox_deviceName.getSelectedIndex();
    int number = Integer.parseInt(getBinaryPrintNum());

    int index = jComboBox_deviceName.getSelectedIndex();
    String deviceName = getDeviceName();
    String deviceType = getDeviceModel();
    String deviceID = getDeviceID(); // MAC
    String manageIP = getManageIP();
    String deviceSN = getDeviceSN();
    // String deviceVresion = getDeviceVersion();
    String power = getPower();
    String officialWebsite = getOfficialWebsite();

    Book book = new Book();
    PageFormat pf = new MyPaperFormat(mainUi);

    // 生成二维码
    productPowerLineQRCode(head, deviceID, deviceSN, manageIP);

    printInfo printinfo = mainUi.new printInfo();

    printinfo.setdeviceID(deviceID);
    printinfo.setManageIP(manageIP);
    printinfo.setDeviceSN(deviceSN);

    printinfo.setdeviceName(deviceName);
    printinfo.setdeviceType(deviceType);
    // printinfo.setDeviceVresion(deviceVresion);
    printinfo.setPower(power);
    printinfo.setOfficialWebsite(officialWebsite);
    printinfo.setCompany(companyInit);
    printinfo.setPowerLineIndex(index);

    myPrint = new MyPrint(printinfo);
    book.append(myPrint, pf);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(book);
    try {
      if (true) {
        job.print();
        mainUi.appendTextareaText(mainUi.jTextArea_status, "\n执行打印");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #6
0
    PrintRenderer(final PrinterJob printerJob, final int copies) {
      super();

      this.printerJob = printerJob;
      this.copies = copies;
      startNumber = 0;
      endNumber = -1;

      printerJob.setPageable(this);
      printerJob.setCopies(this.copies);
      mode = PrintRenderer.EVEN_AND_ALL;
      String str = null;
      if (str != null) {
        try {
          mode = Boolean.valueOf(str).booleanValue() ? PrintRenderer.EVEN : PrintRenderer.ODD;
        } catch (Exception e) {
        }
      }
    }
Пример #7
0
  @Override
  public void print() {

    try {
      File input = new File(absoluteFilePath);
      FileInputStream fis = new FileInputStream(input);
      FileChannel fc = fis.getChannel();
      ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());

      PDFFile curFile = null;
      PDFPrintPage pages = null;
      curFile = new PDFFile(bb); // Create PDF Print Page
      pages = new PDFPrintPage(curFile);
      PrinterJob pjob = PrinterJob.getPrinterJob();

      PrintService[] services = PrinterJob.lookupPrintServices();
      for (PrintService ps : services) {
        String pName = ps.getName();
        if (pName.equals(Profile.getInstance().getDefaultPrinterName())) {
          pjob.setPrintService(ps);
          logger.debug("Printing on : " + pName);
          break;
        }
      }

      pjob.setJobName(absoluteFilePath);
      Book book = new Book();
      PageFormat pformat = PrinterJob.getPrinterJob().defaultPage();
      book.append(pages, pformat, curFile.getNumPages());
      pjob.setPageable(book);

      // print
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

      // Print it
      pjob.print(aset);
      fis.close();
    } catch (Exception e) {
      logger.error("Cannot print pdf", e);
      Dialog.showThrowable("Erreur", "Impossible d'imprimer le fichier", e);
    }
  }
Пример #8
0
 @Override
 public void actionPerformed(ActionEvent e) {
   switch (e.getActionCommand()) {
     case "CHANGE":
       pf = PrinterJob.getPrinterJob().pageDialog(pf);
       setMediaSizeInfo();
       pages.setPageFormat(pf);
       break;
     case "PRINT":
       PrinterJob pjob = PrinterJob.getPrinterJob();
       pjob.setPageable(new MyPageable(pages.getNumberOfPages(), pf, p));
       if (pjob.printDialog() == false) return;
       try {
         pjob.print();
       } catch (PrinterException e1) {
         JOptionPane.showMessageDialog(
             this, "Druckfehler: " + e1.getMessage(), "Fehler", JOptionPane.WARNING_MESSAGE);
       }
       break;
     case "CANCEL":
       setVisible(false);
       break;
   }
 }
Пример #9
0
  public static void startPrinting(
      IApplication application,
      Pageable pageable,
      PrinterJob a_printerJob,
      String a_preferredPrinterName,
      boolean showPrinterSelectDialog,
      boolean avoidDialogs) {
    RepaintManager currentManager =
        RepaintManager.currentManager(application.getPrintingRendererParent().getParent());
    boolean isDoubleBufferingEnabled = false;
    try {
      if (currentManager != null) {
        isDoubleBufferingEnabled = currentManager.isDoubleBufferingEnabled();
      }

      if (a_printerJob != null) {
        // for plugin printing
        a_printerJob.setPageable(pageable);
        a_printerJob.setJobName("Servoy Print"); // $NON-NLS-1$
        if (showPrinterSelectDialog) {
          if (!a_printerJob.printDialog()) {
            return;
          }
          SwingHelper.dispatchEvents(100); // hide dialog
        }
        if (currentManager != null) {
          currentManager.setDoubleBufferingEnabled(false);
        }
        a_printerJob.print();
      } else {
        // by default we use old system for mac, new is not always working
        boolean useSystemPrintDialog =
            Utils.getAsBoolean(
                application
                    .getSettings()
                    .getProperty(
                        "useSystemPrintDialog",
                        "" + Utils.isAppleMacOS())); // $NON-NLS-1$//$NON-NLS-2$
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        if (capablePrintServices == null) {
          capablePrintServices = PrintServiceLookup.lookupPrintServices(flavor, pras);
        }

        PrintService service = null;
        if (capablePrintServices == null || capablePrintServices.length == 0) {
          if (avoidDialogs) {
            Debug.warn("Cannot find capable print services. Print aborted.");
            return;
          } else {
            JOptionPane.showConfirmDialog(
                ((ISmartClientApplication) application).getMainApplicationFrame(),
                application.getI18NMessage("servoy.print.msg.noPrintersFound"),
                application.getI18NMessage(
                    "servoy.print.printing.title"), //$NON-NLS-1$ //$NON-NLS-2$
                JOptionPane.OK_OPTION,
                JOptionPane.ERROR_MESSAGE);
            capablePrintServices = new PrintService[0];
            showPrinterSelectDialog = true; // must show select printer and if none found show this
            useSystemPrintDialog =
                true; // we leave to system to show no printers are found, important for apple mac
          }
        } else {
          service = capablePrintServices[0]; // default select
        }

        PrintService systemDefaultPrinter = PrintServiceLookup.lookupDefaultPrintService();
        if (systemDefaultPrinter != null) {
          // check if system default printer is in capable list
          for (PrintService ps : capablePrintServices) {
            if (ps.getName().equalsIgnoreCase(systemDefaultPrinter.getName())) {
              service = systemDefaultPrinter;
              break;
            }
          }
        }

        boolean didFindPrinter = true; // want custom preferred printer
        if (a_preferredPrinterName != null) {
          didFindPrinter = false;
          for (PrintService ps : capablePrintServices) {
            if (ps.getName().equalsIgnoreCase(a_preferredPrinterName)) {
              didFindPrinter = true;
              service = ps;
              break;
            }
          }
        }

        if (!didFindPrinter) {
          if (avoidDialogs) {
            Debug.warn(
                "Cannot find capable printer for preferred form printer name '"
                    + a_preferredPrinterName
                    + "'. Trying to use default/any capable printer.");
          } else {
            showPrinterSelectDialog = true; // did not found the prefered , do show
          }
        }

        if (!useSystemPrintDialog) {
          if (showPrinterSelectDialog) {
            JFrame frame = ((ISmartClientApplication) application).getMainApplicationFrame();
            GraphicsConfiguration gc = frame.getGraphicsConfiguration();
            Point loc = frame.getLocation();
            service =
                ServiceUI.printDialog(
                    gc, loc.x + 50, loc.y + 50, capablePrintServices, service, flavor, pras);
          }
          if (service != null) {
            if (currentManager != null) {
              currentManager.setDoubleBufferingEnabled(false);
            }
            DocPrintJob job = service.createPrintJob();
            DocAttributeSet das = new HashDocAttributeSet();
            Doc doc = new SimpleDoc(pageable, flavor, das);
            if (job != null) {
              job.print(doc, pras);
            } else {
              // for example if the print service cancels (e.g. print to pdf and then user cancel
              // when choosing save location)
              application.reportWarning(
                  application.getI18NMessage(
                      "servoy.print.error.cannotPrintDocument")); //$NON-NLS-1$
            }
          }
        } else {
          a_printerJob = PrinterJob.getPrinterJob();
          a_printerJob.setPageable(pageable);
          a_printerJob.setJobName("Servoy Print"); // $NON-NLS-1$
          if (service != null) {
            a_printerJob.setPrintService(service);
          }
          if (showPrinterSelectDialog) {
            if (!a_printerJob.printDialog()) {
              return;
            }
            SwingHelper.dispatchEvents(100); // hide dialog
          }
          if (currentManager != null) {
            currentManager.setDoubleBufferingEnabled(false);
          }
          a_printerJob.print();
        }
      }
    } catch (Exception ex) {
      application.reportError(
          application.getI18NMessage("servoy.print.error.cannotPrintDocument"), ex); // $NON-NLS-1$
    } finally {
      if (currentManager != null) {
        currentManager.setDoubleBufferingEnabled(isDoubleBufferingEnabled);
      }
    }
  }
Пример #10
0
  private boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog)
      throws JRException {
    boolean isOK = true;

    if (firstPageIndex < 0
        || firstPageIndex > lastPageIndex
        || lastPageIndex >= jasperPrint.getPages().size()) {
      throw new JRException(
          "Invalid page index range : "
              + firstPageIndex
              + " - "
              + lastPageIndex
              + " of "
              + jasperPrint.getPages().size());
    }

    pageOffset = firstPageIndex;

    PrinterJob printJob = PrinterJob.getPrinterJob();

    // fix for bug ID 6255588 from Sun bug database
    initPrinterJobFields(printJob);

    PageFormat pageFormat = printJob.defaultPage();
    Paper paper = pageFormat.getPaper();

    printJob.setJobName("JasperReports - " + jasperPrint.getName());

    switch (jasperPrint.getOrientation()) {
      case JRReport.ORIENTATION_LANDSCAPE:
        {
          pageFormat.setOrientation(PageFormat.LANDSCAPE);
          paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
          paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
          break;
        }
      case JRReport.ORIENTATION_PORTRAIT:
      default:
        {
          pageFormat.setOrientation(PageFormat.PORTRAIT);
          paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
          paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
        }
    }

    pageFormat.setPaper(paper);

    Book book = new Book();
    book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
    printJob.setPageable(book);
    try {
      if (withPrintDialog) {
        if (printJob.printDialog()) {
          printJob.print();
        } else {
          isOK = false;
        }
      } else {
        printJob.print();
      }
    } catch (Exception ex) {
      throw new JRException("Error printing report.", ex);
    }

    return isOK;
  }
    public void printPage(String size) {
      double width = 0.0;
      double height = 0.0;
      double margin = 0.0;
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
      try {
        PrinterJob pj = PrinterJob.getPrinterJob();
        if (pj.printDialog()) {
          PageFormat pf = pj.defaultPage();
          Paper paper = pf.getPaper();
          if (size.equals("3r")) {
            width = 5d * 72d;
            height = 3.5d * 72d;
            margin = 0d * 72d;
            aset.add(MediaSizeName.JIS_B7);
          } else if (size.equals("4r")) {
            width = 6d * 72d;
            height = 4d * 72d;
            margin = 0d * 72d;
            aset.add(MediaSizeName.JAPANESE_POSTCARD);
          } else if (size.equals("5r")) {
            width = 7d * 72d;
            height = 5d * 72d;
            margin = 0d * 72d;
            aset.add(MediaSizeName.NA_5X7);
          } else if (size.equals("6r")) {
            width = 8d * 72d;
            height = 6d * 72d;
            margin = 0d * 72d;
            aset.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
          } else if (size.equals("8r")) {
            width = 10d * 72d;
            height = 8d * 72d;
            margin = 0d * 72d;
            aset.add(MediaSizeName.NA_8X10);
          }
          paper.setSize(width, height);
          paper.setImageableArea(margin, margin, width - (margin * 2), height - (margin * 2));
          System.out.println("Before- " + dump(paper));
          pf.setOrientation(PageFormat.LANDSCAPE);
          pf.setPaper(paper);
          System.out.println("After- " + dump(paper));
          System.out.println("After- " + dump(pf));
          dump(pf);
          PageFormat validatePage = pj.validatePage(pf);
          System.out.println("Valid- " + dump(validatePage));

          Book pBook = new Book();
          pBook.append(this, pf);
          pj.setPageable(pBook);

          aset.add(OrientationRequested.LANDSCAPE);

          try {
            pj.setPrintable(this);
            pj.print(aset);
          } catch (PrinterException ex) {
            ex.printStackTrace();
          }
        }

      } catch (Exception exp) {
        exp.printStackTrace();
      }
    }
Пример #12
0
  private void printDocument(InvoicePagePrint pageprintdocumnet) {
    PrintService[] service = PrinterJob.lookupPrintServices(); // list
    // of
    // printers
    int count = service.length;
    PrintService printSvc = null;
    for (int i = 0; i < count; i++) {
      System.out.println("Service name: " + service[i].getName());
      if (service[i].getName().indexOf("PDFcamp") != -1) {
        printSvc = service[i];
        i = count;
      }
    }

    // --- Create a new PrinterJob object and set predefined print service.
    try {

      PrinterJob printJob = PrinterJob.getPrinterJob();
      printJob.setPrintService(printSvc);

      PageFormat pf = printJob.defaultPage();
      // Paper paper = pf.getPaper();
      // paper.setSize(8.5 * 72, 11 * 72);
      // paper.setSize(79, 78);

      // paper.setImageableArea(0.5 * 72, 0.0 * 72, 7.5 * 72, 11.5 * 72);
      // paper.setImageableArea(0.5 , 0.0 , 79, 78);
      // pf.setPaper(paper);

      // --- Create a new book to add pages to
      Book book = new Book();

      // --- Add the cover page using the default page format for this
      // print
      // job
      // book.append(pageprintdocumnet, printJob.defaultPage());
      book.append(pageprintdocumnet, pf);

      // Paper pg = new Paper();
      // pg.setSize(1000, 900);
      // book.append(pageprintdocumnet, printJob..defaultPage();

      // --- Add the document page using a landscape page format
      /*
       * PageFormat documentPageFormat = new PageFormat();
       * documentPageFormat.setOrientation(PageFormat.LANDSCAPE); book.append(new Document(),
       * documentPageFormat);
       */
      // --- Add a third page using the same painter

      // --- Tell the printJob to use the book as the pageable object
      printJob.setPageable(book);

      // --- Show the print dialog box. If the user click the
      // --- print button we then proceed to print else we cancel
      // --- the process.
      // if (printJob.printDialog()) {

      printJob.print();
    } catch (Exception PrintException) {
      PrintException.printStackTrace();
    }
  }
Пример #13
0
  /**
   * This is the master print call. All other print calls in this class pass through to here after
   * setting the appropriate parameters. Note that the scale type parameter take precedent over the
   * horizontal and vertical scaling percentages. Therefore, if the scale type was "SCALE_TO_FIT_Y",
   * then the values of horizontal and vertical scaling percentages would not be used.
   *
   * @param scene The Scene to be printed.
   * @param format format used for printing Scene. If null then a new default PageFormat is created.
   * @param scaleStrategy value representing the how to scale the printing.
   * @param scaleX Directly set the horizontal scale percentage. This parameter is only used when
   *     the scale strategy is ScaleStrategy.SCALE_PERCENT. Otherwise it is ignored.
   * @param scaleY Directly set the vertical scale percentage. This parameter is only used when the
   *     scale strategy is ScaleStrategy.SCALE_PERCENT. Otherwise it is ignored.
   * @param selectedOnly Print only the objects from the Scene that have been selected. Note that in
   *     this case the Scene must be an instnace of an ObjectScene since this is required to
   *     determine the selected objects.
   * @param visibleOnly Print only the object in the visible window.
   * @param region The rectangle representing the are of the Scene to be printed.
   * @param hiddenLayerWidgets Layer that are not to be printed. Might be used to hide the
   *     background while printing.
   */
  public static void print(
      Scene scene,
      PageFormat format,
      ScaleStrategy scaleStrategy,
      double scaleX,
      double scaleY,
      boolean selectedOnly,
      boolean visibleOnly,
      Rectangle region,
      List<LayerWidget> hiddenLayers) {

    // quick return if the scene is null
    if (scene == null) return;
    if (scaleStrategy == null) scaleStrategy = ScaleStrategy.NO_SCALING;

    PageableScene ps =
        new PageableScene(
            scene, format, scaleStrategy, scaleX, scaleY, selectedOnly, visibleOnly, region);

    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPageable(ps);

    if (printJob.printDialog()) {

      try {
        // this can not go here because it hides all the widgets everytime.
        ArrayList<Widget> hiddenWidgets = new ArrayList<Widget>();

        if (hiddenLayers != null && hiddenLayers.size() > 0) {
          for (Widget widget : hiddenLayers) {
            widget.setVisible(false);
            hiddenWidgets.add(widget);
          }
        }

        // if selectedOnly is true then we need to hide all the non-selected
        // widgets. Note that if the widgets were already hidden due to hiding
        // a layer, they are not hidden again.
        if (selectedOnly) {
          // in order to use getSelectedObject the scene must be an ObjectScene
          if (scene instanceof ObjectScene) {
            ObjectScene gScene = (ObjectScene) scene;
            // hide unselected widget
            HashSet<Object> invisible = new HashSet<Object>();
            invisible.addAll(gScene.getObjects());
            Set selectedObjects = gScene.getSelectedObjects();
            invisible.removeAll(selectedObjects);

            for (Object o : invisible) {
              Widget widget = gScene.findWidget(o);
              if (widget != null && widget.isVisible()) {
                widget.setVisible(false);
                hiddenWidgets.add(widget);
              }
            }
          }
        }

        // Similar to the selectedOnly, if visibleOnly is true we have to
        // hide the widgets not in the visible window. The reason for this
        // is because setting the size alone does not hide the widgets. Any
        // page that is printed will include all its contained widgets if
        // they are not hidden. Note also that this must work with any
        // Scene, not just the ObjectScene. Therefore, we have to gather
        // all the widgets.
        if (visibleOnly || region != null) {

          // if the region is null, then the user is not trying to print a
          // region. The other way into this condition is if we need to
          // to print the visibleArea. So we set the region to be the
          // visible area.
          if (region == null) region = scene.getView().getVisibleRect();

          List<Widget> allWidgets = new ArrayList<Widget>();
          for (Widget widget : scene.getChildren()) {
            allWidgets.addAll(getAllNodeWidgets(widget, null));
          }

          for (Widget widget : allWidgets) {
            Rectangle widgetInSceneCoordinates = widget.convertLocalToScene(widget.getBounds());
            boolean included = region.contains(widgetInSceneCoordinates);
            if (!included && widget.isVisible()) {
              widget.setVisible(false);
              hiddenWidgets.add(widget);
            }
          }
        }

        printJob.print();

        // restore widget visibility
        for (Widget w : hiddenWidgets) {
          w.setVisible(true);
        }

        scene.validate();

      } catch (PrinterException pe) {
        System.out.println("Error printing: " + pe);
      }
    }
  }