2024年4月26日发(作者:)

package test;

import .*;

import .*;

/*实现套打,把套打的格式当成一张图片,将要填入的数据按其在图片在坐标来定位

*/

public class PrintTest implements Printable {

private String[] value = null;// 所要打印的数据{ "001", "002", "003"};

private int[][] position = null;// 每个数据在图片中的坐标 { { 10, 50 }, { 30, 70 },

{ 50, 90 }};

/**

* implements Printable

* PageFormat类描述了页面的定位信息、它的尺寸以及每英尺可绘制的区域(单位

1/72nd)。

*/

public int print(Graphics g, PageFormat pf, int pageIndex) {

n(pageIndex);

// 只打一页

if (pageIndex > 0) {

return _SUCH_PAGE;

}

Graphics2D g2d = (Graphics2D) g;

for (int i = 0; i < ; i++) {

String str = value[i];

int[] temp = position[i];

int x = temp[0];

int y = temp[1];

// 设置打印字体(字体名称、样式和点大小)