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();
    }
  }
 // 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();
   }
 }
Exemple #3
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);
    }
  }
 protected static String dump(Paper paper) {
   StringBuilder sb = new StringBuilder(64);
   sb.append(paper.getWidth())
       .append("x")
       .append(paper.getHeight())
       .append("/")
       .append(paper.getImageableX())
       .append("x")
       .append(paper.getImageableY())
       .append(" - ")
       .append(paper.getImageableWidth())
       .append("x")
       .append(paper.getImageableHeight());
   return sb.toString();
 }
Exemple #5
0
  /** Convenience method */
  public void print() throws PrinterException {
    //
    // Now, request the transcoder to actually perform the
    // printing job.
    //
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printerJob.defaultPage();

    //
    // Set the page parameters from the hints
    //
    Paper paper = pageFormat.getPaper();

    Float pageWidth = (Float) hints.get(KEY_PAGE_WIDTH);
    Float pageHeight = (Float) hints.get(KEY_PAGE_HEIGHT);
    if (pageWidth != null) {
      paper.setSize(pageWidth.floatValue(), paper.getHeight());
    }
    if (pageHeight != null) {
      paper.setSize(paper.getWidth(), pageHeight.floatValue());
    }

    float x = 0, y = 0;
    float width = (float) paper.getWidth();
    float height = (float) paper.getHeight();

    Float leftMargin = (Float) hints.get(KEY_MARGIN_LEFT);
    Float topMargin = (Float) hints.get(KEY_MARGIN_TOP);
    Float rightMargin = (Float) hints.get(KEY_MARGIN_RIGHT);
    Float bottomMargin = (Float) hints.get(KEY_MARGIN_BOTTOM);

    if (leftMargin != null) {
      x = leftMargin.floatValue();
      width -= leftMargin.floatValue();
    }
    if (topMargin != null) {
      y = topMargin.floatValue();
      height -= topMargin.floatValue();
    }
    if (rightMargin != null) {
      width -= rightMargin.floatValue();
    }
    if (bottomMargin != null) {
      height -= bottomMargin.floatValue();
    }

    paper.setImageableArea(x, y, width, height);

    String pageOrientation = (String) hints.get(KEY_PAGE_ORIENTATION);
    if (VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.PORTRAIT);
    } else if (VALUE_PAGE_ORIENTATION_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.LANDSCAPE);
    } else if (VALUE_PAGE_ORIENTATION_REVERSE_LANDSCAPE.equalsIgnoreCase(pageOrientation)) {
      pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    }

    pageFormat.setPaper(paper);
    pageFormat = printerJob.validatePage(pageFormat);

    //
    // If required, pop up a dialog to adjust the page format
    //
    Boolean showPageFormat = (Boolean) hints.get(KEY_SHOW_PAGE_DIALOG);
    if ((showPageFormat != null) && (showPageFormat.booleanValue())) {
      PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat);
      if (tmpPageFormat == pageFormat) {
        // Dialog was cancelled, meaning that the print process should
        // be stopped.
        return;
      }

      pageFormat = tmpPageFormat;
    }

    // Set printable before showing printer dialog so
    // it can update the pageFormat if it wishes...
    printerJob.setPrintable(this, pageFormat);

    //
    // If required, pop up a dialog to select the printer
    //
    Boolean showPrinterDialog;
    showPrinterDialog = (Boolean) hints.get(KEY_SHOW_PRINTER_DIALOG);
    if (showPrinterDialog != null && showPrinterDialog.booleanValue()) {
      if (!printerJob.printDialog()) {
        // Dialog was cancelled, meaning that the print process
        // should be stopped.
        return;
      }
    }

    // Print now
    printerJob.print();
  }