B4J Library PdfJet Rewrapped

Discussion in 'B4J Libraries & Classes' started by Enrique Gonzalez R, Feb 25, 2018.

  1. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    Hi!

    I do like a lot this library and a lot of people uses it, but the awesome library wrapped by @warwound it is a bit outdated. so i decided to wrap mine, but i have never been able to compile a single line of java so this wrap was made in its entirety with JavaObject,

    I uploaded the B4J Project as i do not know if i can maintain it, and for this first version it is just 3 classes with a single drawString method. Why? well... it is more of a tutorial than a full wrapped library, i think its to easy to see how it was made, so i hope someone finds it useful.

    To work on it i recommend to download the evaluation version of pdfJet here:
    http://pdfjet.com/java/download.html

    In the zipped file you will find pdfJet.jar Version 5.9, copy to your additional jar folder and it should work without further issues.

    In the same zipped file you will find a docs folder, here comes the JavaDocs, those are very good to work with javaobject

    If you need to add any functionality and do not know how, just ask, i will try to find sometime to help!

    EDIT 04/05/2018
    new version with Table class
     

    Attached Files:

    Last edited: May 4, 2018
    BPak, Don Oso, dar2o3 and 4 others like this.
  2. Omar Moreno

    Omar Moreno Member Licensed User

    Hola Enrique.

    Descargue u actualice la librería, tu programa funciona bien, pero cuando añadí una clase para los código de barra me genera errores en el main:

    Code:
    ...
        
    Dim barx As JetBarCode
        barx.Initialize(
    1,"ALI00042")
        barx.setLocation(
    200.0,200.0)
        barx.setModuleLength(
    0.75)
        barx.setFont(
    font)   '<----- da error 
        barx.drawOn(page)
        
    '   
        pdf.close
    ...
    La clase

    Code:
    Sub Class_Globals
        
    Private fx As JFX
        
    Private BarcodeObj As JavaObject
    End Sub

    'Inicializa el objecto. Puede agregar parámetros al metodo si lo necesita.
    '
    'Tipo:  0 = UPC, 1 = CODE128, 2 = CODE39
    'Valor: Cadena de caracteres segun el tipo.
    '
    Public Sub Initialize(Tipo As Int, Valor As String)
        BarcodeObj.InitializeNewInstance(
    "com.pdfjet.BarCode",Array(Tipo,Valor))
    End Sub

    public Sub getObj As Object
        
    Return BarcodeObj
    End Sub

    Public Sub setLocation(x1 As Float, y1 As Float)
        BarcodeObj.RunMethod(
    "setLocation"Array(x1,y1))
    End Sub

    Public Sub setModuleLength(moduleLength As Float)
        BarcodeObj.RunMethod(
    "setModuleLength"Array(moduleLength))
    End Sub

    Public Sub setFont(font As jetFont)
        BarcodeObj.RunMethod(
    "setFont"Array(font))
    End Sub

    Public Sub drawOn(page As JetPage)
        BarcodeObj.RunMethod(
    "drawOn"Array(page))
    End Sub
    el error:

    jetbarcode._setfont (java line: 64)
    java.lang.RuntimeException: Method: setFont not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
    at b4j.example.jetbarcode._setfont(jetbarcode.java:64)
    at b4j.example.main._appstart(main.java:87)
    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.BA.raiseEvent(BA.java:77)
    at b4j.example.main.start(main.java:38)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)


    y si inactivo la linea en el main donde va el setFont me genera otro error en el método barx.drawOn(page).

    jetbarcode._drawon (java line: 42)
    java.lang.RuntimeException: Method: drawOn not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
    at b4j.example.jetbarcode._drawon(jetbarcode.java:42)
    at b4j.example.main._appstart(main.java:87)
    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.BA.raiseEvent(BA.java:77)
    at b4j.example.main.start(main.java:38)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:748)


    Estaré probando los dibujos de lineas.
    Muchas Gracias.
     
  3. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    hi!

    i re uploaded in the first post the library with the corrections

    ... you sure are good! it was missing just this part:


    Code:
    Public Sub setFont(font As jetFont)
        BarcodeObj.RunMethod(
    "setFont"Array(font.obj))
    End Sub
    the font.obj is used to pass the correct Object to the class and not the b4x Class
     
  4. Omar Moreno

    Omar Moreno Member Licensed User

    Correcto!!!, ha funcionado.

    Por hoy la ultima consulta:
    ¿Por qué en la primera generación siempre me salen los textos superpuestos ? y ya desde la segunda funciona bien.

    Primera:

    PDF 1.PNG

    segunda

    PDF 2.PNG

    Gracias.
     
  5. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    No lo se!

    me paso ami tambien, pero despues no me dio un error, y por despues me refiero a todas las demas ejemplo aparte de la primera, como el texto de la licencia tambien aparece asi, me imagino que es por un registro de licencia de la libreria.

    ---------------------------------

    i do not know!!! it happened to me too! just the first time, all the others dont.
     
  6. stevel05

    stevel05 Expert Licensed User

    Thanks for posting this Enrique, it made me look at the PDFJet opensource version which is Free "under a business friendly BSD style license" if you don't need the additional functionality of the commercial version (doesn't do embedded open and truetype fonts and barcodes amongst other things which you can see here: http://pdfjet.com/os/edition.html )

    You can download it from their site and build the jar yourself, or get a slightly older version jar file from here : https://jar-download.com/?detail_search=a:"pdfjet"&a=pdfjet

    You just need to change the jetFont class initialization sub to:

    Code:
    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(pdf As jetPDF, FontName As String)
        
    Dim coreFont As JavaObject
        coreFont.InitializeStatic(
    "com.pdfjet.CoreFont")
        fontObj.InitializeNewInstance(
    "com.pdfjet.Font",Array(pdf.Obj,coreFont.GetField(FontName)))
    End Sub
    The reason this is required is that the OpenSource version has a constructor that uses the arguments (pdf,String) for something else, so it needs to be passed the Enum.

    If want to try the open source version, don't forget to remove the barcode related code from the example program as it is not supported in the open source version.
     
    Last edited: Feb 26, 2018
    inakigarm likes this.
  7. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    hi @stevel05

    it is a very interesting library and among some others it is quite cheap in the paid version.

    thank you for the clarification on the fields, i did not knew how to implement it and that is why i went with the string approach. i am incorporating it in the library!
     
    stevel05 likes this.
  8. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    Updated first post with the table class library, also an example on how to use it.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice