B4J Question data matrix barcode generator offline

sz4t4n

Member
Licensed User
Longtime User
Hi,

i need to generate 2d barcode (data matrix). I can do it with online API's but now i need to do it offline. I found few great libraries for 2d barcodes but there is no data matrix (maybe i missed something). Anyone know how to do it?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Solution based on this jar: http://barcode-coder.com/en/barcode-java-class-204.html
Note that it's license is GPL.

Copy the jar to the additional libraries folder.

SS-2018-05-31_10.12.55.png


B4X:
#AdditionalJar: java-barcode-2.0.3
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private ImageView1 As ImageView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   Dim img As Image = CreateDataMatrix("testing 1 2 3")
   ImageView1.SetLayoutAnimated(0, ImageView1.Left, ImageView1.Top, img.Width, img.Height)
   ImageView1.SetImage(img)
   MainForm.Show
End Sub

Sub CreateDataMatrix(value As String) As Image
   Dim factory As JavaObject
   factory.InitializeStatic("com.barcode_coder.java_barcode.BarcodeFactory")
   Dim barcode As JavaObject = factory.RunMethod("createBarcode", Array("Datamatrix", value))
   Dim f As String = File.Combine(File.DirTemp, "1.png")
   barcode.RunMethod("export", Array("png", 10, 50, True, f))
   Return fx.LoadImage(f, "")
End Sub
 
Upvote 0
Top