我正在尝试打印一个带有非常基本内容的节点
private void print(Node node) {
System.out.println("Creating a printer job...");
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(node.getScene().getWindow()) ) {
System.out.println(job.jobStatusProperty().asString());
PageLayout pageLayout = Printer.getDefaultPrinter().createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);
boolean printed = job.printPage(pageLayout, node);
if (printed) {
System.out.println("Printed.");
job.endJob();
} else {
System.out.println("Printing failed.");
}
} else {
System.out.println("Could not create a printer job.");
}
}
问题是我被DPI分辨率设置为72。这是一种在其他 DPI 分辨率中更改它的方法(无需将尺寸乘以 72.0/wanted_dpi_resolution(?(我的屏幕也是96 DPI(我对能够使用至少为 96 DPI 的 DPI 值进行打印非常感兴趣。
谢谢,等待您的回复。
Meh简短的回答是这是不可能的。
希望这将帮助其他人解决与我相同的问题。请找到附上下一个代码。
public static void printReport(ArrayList<MyPane> nodeList) {
System.out.println("Creating a printer job...");
String printerName = CachedComponents.getPrinterName();
Printer printer = null;
for (Printer p : Printer.getAllPrinters()) {
if (p.getName().equals(printerName)) {
printer = p;
break;
}
}
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
job.getJobSettings().setPrintQuality(PrintQuality.HIGH);
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT,
Printer.MarginType.HARDWARE_MINIMUM);
boolean fail = false;
for (int i=0; i<nodeList.size(); i++) {
MyPane node = nodeList.get(i);
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
node.getTransforms().add(new Scale(scaleX, scaleX));
boolean printed = job.printPage(pageLayout, node);
if (printed) {
System.out.println("Printed.");
} else {
System.out.println("Printing failed.");
fail = true;
}
}
if (!fail) {
job.endJob();
}
} else {
System.out.println("Could not create a printer job.");
}
}
签出空检查。
干杯!