import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
public class OutlineImageableArea {
public static void main(String[] args) {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new OutlinePrintable());
if (pj.printDialog()) {
try { pj.print(); }
catch (PrinterException e) {
System.out.println(e);
}
}
}
}
class OutlinePrintable
implements Printable {
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
double x=pf.getImageableX();
double y=pf.getImageableY();
double dx=pf.getImageableWidth();
double dy=pf.getImageableHeight();
Rectangle2D outline = new Rectangle2D.Double(x,y,dx,dy );
g2.setPaint(Color.black);
g2.draw(outline);
double x1=x+dx/2.0;
double y1=y+dy/2.0;
g2.drawString("Before Affine Transform",(int)x1,(int)y1);
AffineTransform at=AffineTransform.getRotateInstance(Math.PI/8.0,(int)x1,(int)y1);
g2.setTransform(at);
g2.drawString("PI/8 rotate Aff",(int)(x1+5.0),(int)y1);
AffineTransform at=AffineTransform.getRotateInstance(0.0,144,144);
g2.setTransform(new AffineTransform());
g2.drawString("Hello Nurse!",(int)(x1+10.0),(int)y1);
return PAGE_EXISTS;
}
}