我在一個應用程序上工作,這個應用程序是在javafx中,在這個應用程序中我們正在接受食品訂單,這個訂單我們必須用不同的打印機打印,有些打印機會在總部的廚房裏。在我的系統中,我需要打印機列表,當我從應用程序中按下打印按鈕時,我將從列表中選擇打印機。所以打印作業將傳遞給選定的打印機。我將如何在我的javafx應用程序中完成此操作?如何將打印作業傳遞給javafx applcation中的特定打印機?
現在用這個下面的方法,但它傳遞的PrintJob默認它是由系統選擇的不是應用程序了打印機: -
public void print(Node node) {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.NA_LETTER, PageOrientation.PORTRAIT, Printer.MarginType.DEFAULT);
double scaleX = node.getBoundsInParent().getWidth();
double scaleY = node.getBoundsInParent().getHeight();
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
boolean success = job.printPage(node);
if (success) {
job.endJob();
}
}
}
這是怎麼想過去打印機打印工作,而不是從得到print打印機:
ChoiceDialog dialog = new ChoiceDialog(Printer.getDefaultPrinter(), Printer.getAllPrinters());
//ChoiceDialog dialog = new ChoiceDialog(printerName1, printerName2, printerName3, printerName4, printerName5);
dialog.setHeaderText("Choose the printer!");
dialog.setContentText("Choose a printer from available printers");
dialog.setTitle("Printer Choice");
Optional<Printer> opt = dialog.showAndWait();
if (opt.isPresent()) {
Printer printer = opt.get();
PrinterJob job = PrinterJob.createPrinterJob();
job.setPrinter(printer);
if (job != null) {
boolean success = job.printPage(node);
if (success) {
job.endJob();
}
}
}
你好,謝謝你的幫助......我如何獲得更多的一份印刷品? ...我可以給打印機定製名稱嗎? – gurjeet
@gurjeet:這些是2個新問題,或者是a)已經發布在本網站上(儘管還沒有在網站上搜索過),或b)可能對其他用戶有用。所以我不會在評論中回答他們。順便說一句:有時一個簡單的網絡搜索幫助。 – fabian
這是我如何將打印作業傳遞給打印機,但沒有從打印機獲取打印: – gurjeet