在尝试打印到收据单时,java的打印功能遇到问题。连接成功,但是每个打印似乎都在右侧。不太确定如何调整纸张的文本或格式,以使其完全打印。
我用于打印的代码部分(calc是一个TextArea)
Printer printer = Printer.getDefaultPrinter();
if (printer != null)
{
String name = printer.getName();
System.out.println("Default printer name: " + name);
}
else
{
System.out.println("No printers installed.");
}
Paper page = PrintHelper.createPaper("3x10", 76.2, 254, Units.MM);
PageLayout pageLayout = printer.createPageLayout(page, PageOrientation.PORTRAIT, 0, 0, 0, 0);
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
System.out.println(job.jobStatusProperty().asString());
boolean printed = job.printPage(pageLayout, calc);
if (printed) {
job.endJob();
} else {
System.out.println("Printing failed.");
}
} else {
System.out.println("Could not create a printer job.");
}