纸张长宽(3A) 转成 Java 中的pager 类

// 定义毫米到英寸的转换系数
double mmToInch = 1 / 25.4;

// 定义英寸到点的转换系数
double inchToPoint = 72;

// 定义纸张尺寸(单位:毫米)
double paperWidthMm = 420;
double paperHeightMm = 297;

// 将纸张尺寸转换为点
double paperWidthPoints = paperWidthMm * mmToInch * inchToPoint;
double paperHeightPoints = paperHeightMm * mmToInch * inchToPoint;

// 创建一个新的Paper对象,并设置其尺寸和图像打印区域
Paper paper = new Paper();
paper.setSize(paperWidthPoints, paperHeightPoints);
paper.setImageableArea(0, 0, paperWidthPoints, paperHeightPoints);

// 创建一个新的PageFormat对象,并设置其纸张和方向
PageFormat pageFormat = new PageFormat();
pageFormat.setPaper(paper);
pageFormat.setOrientation(PageFormat.PORTRAIT);

猜你喜欢

转载自blog.csdn.net/qq_30346433/article/details/132814681