Ejemplo n.º 1
0
        @Override
        public void run() {
          PrintDialog dialog = new PrintDialog(getViewSite().getShell(), SWT.NONE);
          PrinterData data = dialog.open();
          if (data == null) {
            return;
          }
          if (data.printToFile) {
            data.fileName =
                "print.out"; // TODO you probably want to ask the user for a filename //$NON-NLS-1$
          }

          Printer printer = new Printer(data);
          try {
            Rectangle printerBounds = printer.getClientArea();
            Rectangle trimBounds =
                printer.computeTrim(
                    printerBounds.x, printerBounds.y, printerBounds.width, printerBounds.height);
            System.out.println(printerBounds + ", " + trimBounds); // $NON-NLS-1$

            if (printer.startJob(getPartName())) {
              viewer.print(printer);
              printer.endJob();
            }
          } catch (Throwable e) {
            e.printStackTrace();
          } finally {
            printer.dispose();
          }
        }
Ejemplo n.º 2
0
  private void receivePrinterInfo() {
    dpi = new Point(printer.getDPI());
    pageBounds = new Rectangle(printer.getBounds());
    Rectangle trim = new Rectangle(printer.computeTrim(0, 0, 0, 0));
    pageMargins = new Insets(-trim.y, -trim.x, trim.right(), trim.bottom());

    pageClientArea = new Rectangle(printer.getClientArea());
    //        pageClientArea.x = pageBounds.x
    //                + (pageBounds.width - pageClientArea.width) / 2;
    //        pageClientArea.y = pageBounds.y
    //                + (pageBounds.height - pageClientArea.height) / 2;
    int leftMargin = getUserMargin(PrintConstants.LEFT_MARGIN);
    int rightMargin = getUserMargin(PrintConstants.RIGHT_MARGIN);
    int topMargin = getUserMargin(PrintConstants.TOP_MARGIN);
    int bottomMargin = getUserMargin(PrintConstants.BOTTOM_MARGIN);
    pageClientArea.expand(pageMargins);
    pageClientArea.x += leftMargin;
    pageClientArea.y += topMargin;
    pageClientArea.width -= leftMargin + rightMargin;
    pageClientArea.height -= topMargin + bottomMargin;

    //        needRotate = pageBounds.height > pageBounds.width;
    needRotate = false;
  }