Dim PC As Printer = GetPrinter(myLabelPrinter)
Log("PC") : Log(PC)
Dim myResult As Boolean = False
For Each SP As JavaObject In PC.GetPrinterAttributes.GetSupportedPapers
Dim PP As Paper : PP.Initialize
PP=Paper_static.C
PP.SetObject(SP)
Log("PP") : Log(PP)
Try
Dim VAL As String=PP.tostring
Log("VAL") : Log(VAL)
If VAL.contains("2 x 4")=True Then
Log("PP2") : Log(PP) : Log(PP.GetWidth) : Log(PP.GetHeight)
Dim r As Reflector
r.Target = SP
Log("GetField")
r.setField2("width", 60)
r.SetField2("height", 30)
PP.SetObject(SP)
myResult = True
Exit
End If
Catch
Log(LastException)
End Try
Next
(NoSuchFieldException) java.lang.NoSuchFieldException: width
Thanks SteveWhat are you trying to do?
If the page size you want is not available in GetSupportedPapers, it is unlikely that the printer will respond to the paper size being changed, even if you manage to change it.
The easiest way to use an unavailable paper size would be to choose a larger size, then restrict your layout to the size you actually want to print.
I removed the Try Catch but code just works ok in debug modeCheck your logs, you should be seeing an entry:
B4X:(NoSuchFieldException) java.lang.NoSuchFieldException: width
The paper class does not have a field for width and height. It is not configurable.
Better still remove the Try Catch block until the code is working.
#VirtualMachineArgs: --add-opens javafx.graphics/javafx.print=ALL-UNNAMED
#PackagerProperty : VMArgs = --add-opens javafx.graphics/javafx.print=b4j
Dim Units As JavaObject
Units.InitializeStatic("com.sun.javafx.print.Units")
Dim PrintHelper As JavaObject
PrintHelper.InitializeStatic("com.sun.javafx.print.PrintHelper")
Dim Paper As JavaObject = PrintHelper.RunMethod("createPaper",Array("60mm x 30mm",60.0,30.0,Units.GetField("MM")))
Log(Paper)
#PackagerProperty : VMArgs = --add-opens javafx.graphics/com.sun.javafx.print=b4j
thanks a lot, SteveYou will need to add something like:
To the top of you main Module.B4X:#VirtualMachineArgs: --add-opens javafx.graphics/javafx.print=ALL-UNNAMED
And
If you want to build a package.B4X:#PackagerProperty : VMArgs = --add-opens javafx.graphics/javafx.print=b4j
I can't test it as I don't get the same errors, which is why I am wondering which version you are using.
thanks, SteveThis is a better way of creating a Custom Paper rather than hacking an existing instance:
B4X:Dim Units As JavaObject Units.InitializeStatic("com.sun.javafx.print.Units") Dim PrintHelper As JavaObject PrintHelper.InitializeStatic("com.sun.javafx.print.PrintHelper") Dim Paper As JavaObject = PrintHelper.RunMethod("createPaper",Array("60mm x 30mm",60.0,30.0,Units.GetField("MM"))) Log(Paper)
You will still need the --add-opens directives above plus:
To package the project.B4X:#PackagerProperty : VMArgs = --add-opens javafx.graphics/com.sun.javafx.print=b4j
Yes SteveHave you added the VirtualMachineArg directive in post #9 ?
Hi SteveThis is a better way of creating a Custom Paper rather than hacking an existing instance:
B4X:Dim Units As JavaObject Units.InitializeStatic("com.sun.javafx.print.Units") Dim PrintHelper As JavaObject PrintHelper.InitializeStatic("com.sun.javafx.print.PrintHelper") Dim Paper As JavaObject = PrintHelper.RunMethod("createPaper",Array("60mm x 30mm",60.0,30.0,Units.GetField("MM"))) Log(Paper)
You will still need the --add-opens directives above plus:
To package the project.B4X:#PackagerProperty : VMArgs = --add-opens javafx.graphics/com.sun.javafx.print=b4j
HiDid you put the following in your project? It works for me
#VirtualMachineArgs: --add-opens javafx.graphics/com.sun.javafx.print=ALL-UNNAMED
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?