コード例 #1
0
  public void PrintSingles() {
    if (Mechs.size() == 0) {
      return;
    }

    page.setPaper(paper);

    if (useDialog) {
      if (Mechs.size() == 1) {
        if (!PrintDialog((PrintMech) Mechs.get(0))) return;
      } else {
        if (!BatchDialog()) return;
      }
    }

    for (int index = 0; index <= Mechs.size() - 1; index++) {
      PrintMech pm = (PrintMech) Mechs.get(index);
      job.setJobName(pm.CurMech.GetFullName().trim());
      job.setPrintable(pm);
      try {
        job.print();
      } catch (PrinterException ex) {
        Logger.getLogger(Printer.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #2
0
  public void print(HashPrintRequestAttributeSet aset) {

    try {
      for (int pos = 0; pos < smallCraftList.size(); pos++) {
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintService(masterPrintJob.getPrintService());

        aset.add(PrintQuality.HIGH);

        PageFormat pageFormat = new PageFormat();
        pageFormat = pj.getPageFormat(null);

        Paper p = pageFormat.getPaper();
        p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
        pageFormat.setPaper(p);

        pj.setPrintable(this, pageFormat);
        smallCraft = smallCraftList.get(pos);
        pj.setJobName(smallCraft.getChassis() + " " + smallCraft.getModel());

        try {
          pj.print(aset);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
        System.gc();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
コード例 #3
0
  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();
    }
  }
コード例 #4
0
ファイル: PrintAction.java プロジェクト: jasonchaffee/VUE
    private void runDialogsAndPrint() throws java.awt.print.PrinterException {
      out("job starting for " + this.map);
      PrinterJob job = getPrinterJob();
      out("got OS job: " + tufts.Util.tags(job));
      if (job.printDialog()) {
        out("printDialog ran, waiting for format...");
        // PageFormat format = getPageFormat(job, bounds);
        PageFormat format = getPageFormatInteractive(job, bounds);
        out("format: " + outpf(format));
        if (format != null) {
          job.setJobName(jobName);
          job.setPrintable(this, format);
          // try setting pageable to see if it then
          // skips system dialog (we'd like a no-dialog option)
          // job.setPrintService(job.getPrintService());

          // this only *sometimes* works as a workaround
          // for the vue ap mysteriously being raised above
          // the system print dialog...
          // VUE.frame.toBack();

          out("printing...");
          job.print();
        }
      }
      out("job complete.");
    }
コード例 #5
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);
   }
 }
コード例 #6
0
  public void printableJob(Printable printable) 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();
      }

      if (mediaName == null) {
        Object media = svc.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName) {
          mediaName = (MediaSizeName) media;
          mediaSize = MediaSize.getMediaSizeForName(mediaName);
        }
      }

      if (orient == null) {
        orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
      }

      job.setCopies(copies);
      job.setJobName(jobName);
      PageFormat pf = new PageFormat();
      if (mediaSize != null) {
        Paper p = new Paper();
        p.setSize(mediaSize.getX(MediaSize.INCH) * 72.0, mediaSize.getY(MediaSize.INCH) * 72.0);
        p.setImageableArea(72.0, 72.0, p.getWidth() - 144.0, p.getHeight() - 144.0);
        pf.setPaper(p);
      }
      if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
        pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
      } else if (orient == OrientationRequested.LANDSCAPE) {
        pf.setOrientation(PageFormat.LANDSCAPE);
      }
      job.setPrintable(printable, pf);
      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);
    }
  }
コード例 #7
0
  private void GeneratePrints() {
    // reset the book so we don't get extra pages!
    pages = new Book();

    // start building the print objects necessary
    page.setPaper(paper);

    for (int index = 0; index <= Mechs.size() - 1; index++) {
      PrintMech pm = (PrintMech) Mechs.get(index);
      pages.append(pm, page);
      if (Mechs.size() == 1) job.setJobName(pm.CurMech.GetFullName().trim());
    }
  }
コード例 #8
0
  private static void print(final Image img, String size) {
    PrinterJob printjob = PrinterJob.getPrinterJob();
    printjob.setJobName("Print");

    ImgPrinter printable = new ImgPrinter(img);

    try {
      System.out.println("Printing.");
      printable.printPage(size);
    } catch (Exception ex) {
      System.out.println("NO PAGE FOUND." + ex);
    }
  }
コード例 #9
0
 /**
  * Prints the gnomon.
  *
  * @param evt print
  */
 private void jMenuItemPrintActionPerformed(java.awt.event.ActionEvent evt) {
   PrinterJob job = PrinterJob.getPrinterJob();
   job.setJobName("Gnomon-and-sundial"); // $NON-NLS-1$
   job.setPrintable(this);
   boolean doPrint = job.printDialog();
   if (doPrint) {
     try {
       job.print();
     } catch (PrinterException fail) {
       JOptionPane.showMessageDialog(null, fail);
     }
   }
 }
コード例 #10
0
  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());
      }
    }
  }
コード例 #11
0
 /** Handles the "Print" user action. Shows a printer dialog and prepares the page for printing */
 public void print() {
   PrinterJob pj = PrinterJob.getPrinterJob();
   pj.setPrintable(this);
   pj.setJobName(Messages.getString("GCUPrintJob"));
   if (pj.printDialog()) {
     try {
       pj.print();
     } catch (PrinterException e) {
       JOptionPane.showMessageDialog(
           this,
           Messages.format("PrinterException", e.getLocalizedMessage()), // $NON-NLS-1$
           Messages.getString("Main.16"),
           JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
     }
   }
 }
コード例 #12
0
  public void print() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pageFormat = job.defaultPage();
    Paper paper = pageFormat.getPaper();

    paper.setImageableArea(
        0.0D, 0.0D, pageFormat.getPaper().getWidth(), pageFormat.getPaper().getHeight());
    pageFormat.setPaper(paper);

    job.setJobName(documentTitle);
    job.setPrintable(this, pageFormat);
    if (job.printDialog())
      try {
        job.print();
      } catch (PrinterException ex) {
        JOptionPane.showMessageDialog(null, "Failed to print" + ex);
      }
  }
コード例 #13
0
 // Print image
 public void printImage() {
   PrinterJob printJob = PrinterJob.getPrinterJob();
   PageFormat pf = printJob.defaultPage();
   pf.setOrientation(PageFormat.LANDSCAPE);
   ////////////////////////////////////////
   Paper paper = new Paper();
   paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
   pf.setPaper(paper);
   printJob.setPrintable(this, pf);
   printJob.setJobName("Custom Waiver");
   System.out.println(paper.getWidth() + " " + paper.getHeight());
   try {
     printJob.print();
     // justPrint();
   } catch (Exception PrintException) {
     PrintException.printStackTrace();
   }
 }
コード例 #14
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);
    }
  }
コード例 #15
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);
      }
    }
  }
コード例 #16
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;
  }