I am using the jFX8Print Library Version 0.7
I am using a Xprinter XP-365B Thermal Label printer.
My Label size is 39mm(W) X 18mm(H)
On my Windows 10 PC, the Xprinter is set as "Default Printer"
The Printer Preferences has only 1 paper size set - 39mm(W) X 18mm(H)
The printer works great and I have tested it with the Xprinter Test software.
My B4J app has a Panel "pnlQR" which has 2 X imageviews and 2 X labels.
The imageviews display the QR Barcodes, the labels display a text.
I use:
to take a snapshot of pnlQR.
I must then send this to the printer with btnPrint_Click (No Dialogs):
However, I have the following error:
If I send this to the printer with btnReprint_Click (With Dialogs):
I receive the following error:
I have attached my app ZIP file.
I am using a Xprinter XP-365B Thermal Label printer.
My Label size is 39mm(W) X 18mm(H)
On my Windows 10 PC, the Xprinter is set as "Default Printer"
The Printer Preferences has only 1 paper size set - 39mm(W) X 18mm(H)
The printer works great and I have tested it with the Xprinter Test software.
My B4J app has a Panel "pnlQR" which has 2 X imageviews and 2 X labels.
The imageviews display the QR Barcodes, the labels display a text.
I use:
B4X:
Dim m As Image = MainForm.RootPane.Snapshot
Dim cv As Canvas
cv.Initialize("")
cv.DrawImage(m,0,0,100,60)
I must then send this to the printer with btnPrint_Click (No Dialogs):
B4X:
Private Sub btnPrint_Click
Dim m As Image = MainForm.RootPane.Snapshot
Dim cv As Canvas
cv.Initialize("")
cv.DrawImage(m,0,0,100,60)
Dim P As Printer = Printer_Static.GetDefaultPrinter
' Dim P As Printer = GetPrinter("Xprinter XP-365B")
Dim PA As PrinterAttributes = P.GetPrinterAttributes
Dim p_paper As Paper = PA.GetDefaultPaper
Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(p)
pl = p.CreatePageLayout(p_paper,"PORTRAIT",1,1,1,1) ' You should change orientation and margin If Neccessary
PJ.GetJobSettings.SetCopies(1)
PJ.GetJobSettings.SetPageLayout(pl)
PJ.GetJobSettings.SetPrintQuality("HIGH")
PJ.GetJobSettings.SetJobName("QR_PRINTER")
Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
PJ.PrintPage(pnlQR)
PJ.EndJob
End Sub
However, I have the following error:
B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 35 (Paper)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.printer._createpagelayout(printer.java:80)
at b4j.example.main._btnprint_click(main.java:143)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:234)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at com.sun.prism.j2d.print.J2DPrinter.getMediaSizeName(J2DPrinter.java:832)
at com.sun.prism.j2d.print.J2DPrinter.printableArea(J2DPrinter.java:848)
at javafx.print.Printer.createPageLayout(Printer.java:349)
... 28 more
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
B4X:
Private Sub btnReprint_Click
Dim m As Image = MainForm.RootPane.Snapshot
Dim cv As Canvas
cv.Initialize("")
cv.DrawImage(m,0,0,100,60)
Dim P As Printer = Printer_Static.GetDefaultPrinter
' Dim P As Printer = GetPrinter("Xprinter XP-365B")
Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
PJ.ShowPageSetupDialog(Null)
PJ.ShowPrintDialog(Null)
PJ.PrintPage(pnlQR)
PJ.EndJob
End Sub
B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 67 (PrinterJob)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.printerjob._showpagesetupdialog(printerjob.java:105)
at b4j.example.main._btnreprint_click(main.java:200)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:234)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at com.sun.prism.j2d.print.J2DPrinter.getMediaSizeName(J2DPrinter.java:832)
at com.sun.prism.j2d.print.J2DPrinter.printableArea(J2DPrinter.java:848)
at javafx.print.Printer.createPageLayout(Printer.java:249)
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.showPageDialog(J2DPrinterJob.java:240)
at javafx.print.PrinterJob.showPageSetupDialog(PrinterJob.java:343)
... 28 more
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
Attachments
Last edited: