B4J Library PdfJet Rewrapped

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

EDIT 22/08/2018
new initializations for font

EDIT 27/08/2018
new drawRect in page,
 

Attachments

Last edited:

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:

B4X:
...
    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

B4X:
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.
 

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:


B4X:
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
 

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.
 

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.
 

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:

B4X:
'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 you 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:

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!
 

moore_it

Well-Known Member
Licensed User
Hi Enrique, i need to change the corefont in an unicode font for draw text type this "Fuškulin".
It'ìs possible ?

Thanks in advice
 

Enrique Gonzalez R

Well-Known Member
Licensed User
Hi Enrique, i need to change the corefont in an unicode font for draw text type this "Fuškulin".
It'ìs possible ?

Thanks in advice
Yes! in the first post you will find how to do it, i modified the jetFont class, because we cannot create an Initialize2 that overrides initialize, so you may need to change some code in order to use it.
 

moore_it

Well-Known Member
Licensed User
Hi Enrique,

why that ?

Waiting for debugger to connect...
Program started.
Errore nella linea: 15 (jetPDF)
java.lang.RuntimeException: Constructor not found.
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
at b4j.example.jetfont._initialize2(jetfont.java:86)
at b4j.example.main._appstart(main.java:120)
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 b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

I use PDFJET-5.75.jar
yesterday your program work fine ....
 

moore_it

Well-Known Member
Licensed User
in pdf page insert this ...

B4X:
public Sub drawRect(x1 As Double,y1 As Double,w As Double,h As Double,fill As Boolean)
    If fill Then
        pageObj.RunMethod("fillRect",Array(x1,y1,w,h))
    Else
        pageObj.RunMethod("drawRect",Array(x1,y1,w,h))   
    End If
End Sub
 

EDragoev

New Member
It seems that Embeding ttf or otf in pdfjet is only for the paid version.
Hi Enrique,

This is correct however the Open Source version can use .ttf.stream and .otf.stream fonts that are included in the package.
Loading stream fonts is much faster and they are identical in appearance to the .ttf and .otf fonts from which whey were derived.

Regards,

Eugene
PDFjet Developer
 

GanjaKyp

Active Member
Licensed User
Why this error hapens?

B4X:
jetfont._initialize2 (java line: 71)
    java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
    at b4j.example.jetfont._initialize2(jetfont.java:71)
    at b4j.example.main._appstart(main.java:94)
    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:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.start(main.java:37)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
    at java.lang.Thread.run(Thread.java:748)
 

Attachments

Top