TSC ttp 244 Plus中的JavaFX条形码标签优先处理-给定异常-java.lang.IllegalArgumentException:不良边距

时间:2018-12-30 16:57:40

标签: java javafx javafx-2 thermal-printer barcode-printing

我正在用JavaFX Application的TSC TTP 244 Plus打印珠宝的条形码标签。我收到以下异常

Caused by: java.lang.IllegalArgumentException: Bad margins
at javafx.print.PageLayout.<init>(PageLayout.java:109)
at javafx.print.Printer.createPageLayout(Printer.java:307)
at javafx.print.Printer.getDefaultPageLayout(Printer.java:221)
at javafx.print.JobSettings.pageLayoutProperty(JobSettings.java:1097)
at javafx.print.JobSettings.getPageLayout(JobSettings.java:1133)
at com.sun.prism.j2d.print.J2DPrinterJob.syncPageLayout(J2DPrinterJob.java:615)
at com.sun.prism.j2d.print.J2DPrinterJob.syncSettingsToAttributes(J2DPrinterJob.java:564)
at com.sun.prism.j2d.print.J2DPrinterJob.showPrintDialog(J2DPrinterJob.java:169)
at javafx.print.PrinterJob.showPrintDialog(PrinterJob.java:299)
at com.mjstock.UI.Controllers.StockController.printBarcodeFinal(StockController.java:710) 

并非所有Windows系统都存在此问题。我试图放置自定义纸张  甚至尝试将margin保持为零,但这没有用。代码如下:

    public void printBarcodeFinal(){

    double valInMM = 72.0f; 

    Screen screen = Screen.getPrimary();
    double dpi = screen.getDpi();

    System.out.println("DPI: " + dpi);
    System.out.println("VBOXDimen: Height - "+String.valueOf(vbox_new.getHeight())+", Width - "+String.valueOf(vbox_new.getWidth()));

    double paperHeight = (vbox_new.getHeight() * valInMM);
    double paperWidth = ((vbox_new.getWidth()) * valInMM);

    System.out.println("SizeInPoints: Height - "+paperHeight+", Width - "+paperWidth);

    PrinterJob job = PrinterJob.createPrinterJob();
    Printer printer = Printer.getDefaultPrinter();

    PageLayout pageLayout = printer.createPageLayout(Paper.C,PageOrientation.PORTRAIT,
            0,0,0,0);
    showLogs("PageLayoutDetails","PageLayout - "+String.valueOf(pageLayout.toString()));

    if (job != null) {
        boolean status = job.showPrintDialog(getMainApp().mainStage);
        if(status){
            job.setPrinter(printer);
            job.getJobSettings().setPageLayout(pageLayout);
            job.getJobSettings().setJobName("MJ_Stock_Barcode_Print");
            job.printPage(vbox_new);
            boolean result = job.endJob();
            if(result){
                showLogs("Status","Print Job Ended!!!");
                btnPrintFinal.setVisible(false);
                listView.setVisible(false);
                vbox_new.getChildren().clear();
                vbox_new.setVisible(false);
            }
        }
        else{
            showLogs("NoSelection","Job is cancelled");
        }
    }
}

0 个答案:

没有答案