public class MyPrintTest
implements Printable
{
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
Graphics2D g2 = (Graphics2D) graphics;
g2.setPaint(Color.black);
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
Font font = new Font("宋体", Font.BOLD, 10);
g2.setFont(font);
g2.drawString("afasdfad", 10, 10);
font = new Font("黑体", Font.ITALIC, 18);
g2.setFont(font);
g2.drawString("第二行:", 10, 40);
return Printable.PAGE_EXISTS;
}
public static void main(String[] args)
{
MyPrintTest myprinttest = new MyPrintTest();
myprinttest.print();
}