B4J Question B4J Printing in Windows with JFX8

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All
I Built a form to act as my report layout to print using JavaFX8 Lib, and I am printing in a USB windows POS printer.

It has no standard paper size,like A4, A5, etc, instead it used a 80mm X user defined length

I can print everthing correctly with the execption of the margins.
I am getting huge margins when i should get 0. is there a way to set 0 margins so it prints the form near to the paper margin ?

Any Ideas ?
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
I have done some more experiments and I always get an error.
Can anyone help, please

my code:

B4X:
    PrintForm.Initialize("PrintForm", 200,200)
    PrintForm.RootPane.LoadLayout("ticket") 'Load the layout file.
    printer_label_pax.text=CurRnd
    'printer_datetime.text = $"${datetime.date(datetime.now)} - ${datetime.time(datetime.now)}"$
   
    Dim PP As Paper
    PP.Initialize()
   
    Dim PC As Printer
    PC.Initialize()
   
    Dim PL As PageLayout
    PL.Initialize()
   
    PP = Paper_static.A6
    PC = Printer_Static.GetDefaultPrinter
    PL = PC.CreatePageLayout2(PP, PageOrientation_Static.PORTRAIT, "HARDWARE_MINIMUM")
   
    Dim PJ As PrinterJob
    PJ = PrinterJob_Static.CreatePrinterJob2(PC) 'CreatePrinterJob
    PJ.PrintPage2(PL, PrintForm.RootPane)
    PJ.EndJob

the error in the log:

B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 342 (Main)
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:131)
    at b4j.example.printer._createpagelayout2(printer.java:62)
    at b4j.example.main._printticket(main.java:896)
    at b4j.example.main._iconprinter_mouseclicked(main.java:846)
    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:628)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
    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:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:93)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
    at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
 
Upvote 0
Top