java print api - 以 300dpi 打印 JComponent
如果我做错了什么,请告诉我。 我想将条形码打印到标签上,因此我需要这些条形码的高质量打印输出,因此我推动打印机以 300dpi 进行打印。 我所做的:
制作了一个大的 JFrame; 宽度:2490px,高度:3515px,因此它代表1:1尺寸的A4纸(如果打印为300dpi,则这是A4纸分辨率)
在该 JFrame 的 contentPane 上绘制 40 个条形码图像
设置打印属性,以便以 300dpi 打印:
PrintRequestAttributeSet aset = 新的 HashPrintRequestAttributeSet();
PrinterResolution pr =
new PrinterResolution(300,300,PrinterResolution.DPI);
MediaPrintableArea mpa=new MediaPrintableArea(8,21,
210-16, 296-42, MediaPrintableArea.MM);
属性集填充了以下数据:
aset.add( mpa );
aset.add( pr );
aset.add( MediaSizeName.ISO_A4 );
aset.add( new Copies(1) );
aset.add(OrientationRequested.PORTRAIT );
aset.add(PrintQuality.HIGH);
aset.add( Fidelity.FIDELITY_TRUE );
printJob.setPrintable(this);
printJob.print(aset);
此类有打印方法:
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}
我需要在那张 A4 纸上有 40 个条形码,每个尺寸为 48.5 毫米 x 25.4 毫米。 打印在纸上的是6个条形码,每个条形码的尺寸为104mm x 46mm(即宽度几乎是页面宽度的一半),占满了整张纸。
任何想法,我能做错什么?
please tell me if I am doing something wrong. I want to print barcodes onto labels, so I need high quality printout for these barcodes so I am pushing printer to print in 300dpi. What I've done:
made a big JFrame; width: 2490px, height: 3515px so it represents A4 paper in 1:1 measure (this is A4 paper resolution if print is to be 300dpi)
draw 40 barcode images onto contentPane of that JFrame
setup print attributes so it will print in 300dpi:
PrintRequestAttributeSet aset =
new HashPrintRequestAttributeSet();
PrinterResolution pr =
new PrinterResolution(300,300,PrinterResolution.DPI);
MediaPrintableArea mpa=new MediaPrintableArea(8,21,
210-16, 296-42, MediaPrintableArea.MM);
attribute set is filled with this data:
aset.add( mpa );
aset.add( pr );
aset.add( MediaSizeName.ISO_A4 );
aset.add( new Copies(1) );
aset.add(OrientationRequested.PORTRAIT );
aset.add(PrintQuality.HIGH);
aset.add( Fidelity.FIDELITY_TRUE );
printJob.setPrintable(this);
printJob.print(aset);
this class has print method:
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}
I need to have 40 barcodes on that A4 sheet, each in size 48.5mm x 25.4mm.
What is printed out on paper is 6 barcodes each doubled in size of 104mm x 46mm (that is in width almost half of page's width) which fulfilled whole paper.
Any idea, what can I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的分辨率可能设置为 72 dpi,这会增加图像的大小。
Your resolution is probably being set to 72 dpi which has the effect of increasing the size of the image.