HI Erel
I have a problem with Reflector
please tell me the solution
my code is this:
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
but I got java error on SetField2 in release mode not in debug mode
java.lang.reflect.InaccessibleObjectException: Unable to make field private double javafx.print.Paper.width accessible: module javafx.graphics does not "opens javafx.print" to unnamed module @537c850b
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.
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
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 mode
but in release mode I get Java error:
java.lang.reflect.InaccessibleObjectException: Unable to make field private double javafx.print.Paper.width accessible: module javafx.graphics does not "opens javafx.print" to unnamed module @59456f4e
at java.base/java.lang.reflect.Field.setAccessible(Field.java:170)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
This 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:
This 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:
thanks, Steve
I used this code but I got this java error:
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.javafx.print.Units (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.print to unnamed module @e05be4e
This 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: