我无法打印超过(几乎)A4高度纸张尺寸的热敏收据(8厘米)。程序仅打印(直到几乎默认)A4尺寸。收货的其余部分丢失了。
小收据一切正常。只有长收据才会出现问题,因为票据缩短了。我动态设置纸张高度计数要打印的行。我也尝试手动将纸张尺寸和imageablearea设置为大尺寸,但是徒劳无功。
我尝试使用Print.Book
类对象,但没有任何改进。
(注意:用另一种语言编写的另一个程序,在同一台打印机上打印相同的帐单)
如果我遗漏了某些内容或如何删除此限制,请告诉我。
public void printReciept()
{
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new BillPrintable(),getPageFormat(pj));
try {
pj.print();
}
catch (PrinterException ex) {
ex.printStackTrace();
}
}
public PageFormat getPageFormat(PrinterJob pj)
{
PageFormat pf = pj.defaultPage();
Paper paper = pf.getPaper();
double middleHeight =this.productList.size()*1.0; //dynamic----->change with the row count of jtable
double headerHeight = 5.0; //fixed----->but can be mod
double footerHeight = 5.0; //fixed----->but can be mod
double width = convert_CM_To_PPI(8); //printer know only point per inch.default value is 72ppi
double height = convert_CM_To_PPI(headerHeight+middleHeight+footerHeight);
paper.setSize(width, height);
paper.setImageableArea(
0,
10,
width,
height - convert_CM_To_PPI(1)
); //define boarder size after that print area width is about 180 points
pf.setOrientation(PageFormat.PORTRAIT); //select orientation portrait or landscape but for this time portrait
pf.setPaper(paper);
return pf;
}
public class BillPrintable implements Printable {
@Override
public int print(Graphics graphics, PageFormat pageFormat,int pageIndex)
throws PrinterException
{
String title[] = {"Product Name","Disc","Rate","Qty","AMT"};
int result = NO_SUCH_PAGE;
if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D) graphics;
g2d.translate((int) pageFormat.getImageableX(),(int) pageFormat.getImageableY());
***** Below will be Code to print bill records *****
}
}