@Override
  public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    if (page > 0) {
      return NO_SUCH_PAGE;
    }

    int i = pf.getOrientation();

    // get the size of the page
    double pageWidth = pf.getImageableWidth();
    double pageHeight = pf.getImageableHeight();
    double myWidth = this.getWidth(); // - borderWidth * 2;
    double myHeight = this.getHeight(); // - borderWidth * 2;
    double scaleX = pageWidth / myWidth;
    double scaleY = pageHeight / myHeight;
    double minScale = Math.min(scaleX, scaleY);

    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());
    g2d.scale(minScale, minScale);

    drawPlot(g);

    return PAGE_EXISTS;
  }
Пример #2
0
        public int print(Graphics g,PageFormat pf,int pageIndex) {

                if (pageIndex == 0) {
                        Graphics2D g2d= (Graphics2D)g;
                        g2d.translate(pf.getImageableX(), pf.getImageableY()); 
                        g2d.setColor(Color.black);
                        g2d.drawString("example string", 250, 250);
                        g2d.fillRect(0, 0, 200, 200);
                        return Printable.PAGE_EXISTS;                                   
                } else {
                        return Printable.NO_SUCH_PAGE;
                }
        }
Пример #3
0
 /** [Internal] */
 public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
   if (pi >= 1) {
     return Printable.NO_SUCH_PAGE;
   }
   RepaintManager currentManager = RepaintManager.currentManager(this);
   currentManager.setDoubleBufferingEnabled(false);
   Graphics2D g2 = (Graphics2D) g;
   initState(g2, true);
   g2.translate((int) (pf.getImageableX() + 1), (int) (pf.getImageableY() + 1));
   g2.scale(printScale, printScale);
   doBuffer(g2, true, null);
   currentManager.setDoubleBufferingEnabled(true);
   return Printable.PAGE_EXISTS;
 }