B4J Library jPDFjet

jPDFjet is a PDF document authoring library for B4J

jPDFjet wraps the PDFjet for Java library from pdfjet.com.
Here are some of it's features:

Drawing support for:
  • Points
  • Lines
  • Boxes
  • Circles
  • Bezier Curves
  • Polygons
  • Stars
  • Complex paths and shapes

Text
  • Unicode support
  • Text kerning when using the Helvetica and Times-Roman families of core fonts
  • Embedding hyperlinks
  • Support for embedding OpenType and TrueType fonts
  • Support for the fonts included with Reader 7.0 and Reader 8.0 installations

Embedding of the following types of images:
  • PNG
  • JPEG
  • BMP

High level components:
  • Simple to use Table class with flexible reporting capabilities
  • Flexible Chart component with support for scatter plots and lines
  • TextColumn component with text kerning and justification support
  • Support for Code 39 and Code 128 barcodes
  • Support for PDF417 and QR code 2D barcodes

PDFjet for Java is available under Open Source, free evaluation and paid for licenses.
jPDFjet can be used with all three licenses.
The Open Source Edition is feature limited.
jPDFjet wraps all available features of the paid for license version - any features that are not available in the Open Source Edition will show in the B4J IDE but not be available for use.
Trying to use a feature that is not available is like to raise a ClassNotFound exception.


In order to use jPDFjet you will need to:
When downloading either version you will agree to and accept the license terms and conditions that apply to the version you download.

EDIT: Please read post #2 in this thread to find out about the available versions of PDFjet for Java.

Your PDFjet for Java download will contain the java library file PDFjet.jar.
Copy PDFjet.jar to your B4J additional libraries folder.

Now download the attached jPDFjet library files and copy these to your B4J additional library folder.
Your B4J additional libraries folder should now contain: jPDFjet.jar, jPDFjet.xml and PDFjet.jar.
jPDFjet.html is for reference only - you don't need to copy this file to your additional libraries folder.

If you upgrade from the Open Source Edition or from the free version to the paid for version you just need to overwrite the Open Source Edition or free version of PDFjet.jar with your paid for version of PDFjet.jar.
One thing i have not done is to add a lot of the javadoc reference to the B4J library.
Many methods are self-explanatory, some are obscure and some lack any javadoc reference.
In your download from pdfjet.com there is a folder docs/java which contains the PDFjet for Java javadoc reference.
Open docs/java/index.html in your browser to see all the available reference/documentation.

There are some java examples of usage of PDFjet both online and in the download from pdfjet.com.
I have converted some of these java examples to B4J and the attached B4J demo project contains those converted examples.

Note that i have also created a B4A version of this library and shall upload the B4A version shortly.
Both B4A and B4J versions share the same syntax.

Library files and demo project attached.

Martin.
 

Attachments

  • jPDFjet-demo-project.zip
    67 KB · Views: 3,340
  • jPDFjet-library_files-v1.10.zip
    78.9 KB · Views: 4,098
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Excuse my English (Translated with Google).

Greetings Enrique.

I have tested with version 1.10 of JPdfJet, but it does not work to generate bar codes.

You could upload a simple example in ZIP to see the operation of this library, since the IDE gives me an error in this line "public Sub addPage (pageOB As Page)".

I have used the PDFJet library creating a Java file which I then convert with the Simple Library Compiler utility, something similar to a Wrapper and it works, but since I do not have much experience in Java it is difficult for me to create a wrapper to generate any PDF document and not one for each PDF.

Thanks for the help you can give me.

hi omar!

hablas español? tenemos un rincon para eso!
https://b4x.com/android/forum/forums/spanish-forum.12/


I rewrapped the library with B4x Code. you can find it here:
https://b4x.com/android/forum/threads/pdfjet-rewrapped.89973/
 

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everybody, i have a strange behavior with bellow code, if i put a break point at line :
B4X:
Dim rowElementsList() As String=tv.Items.Get(i)
then step forward the code runs ok , otherwise i got the following error :
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
at b4j.example.mpdf._createpdftable(mpdf.java:181)
at b4j.example.cls_catalog_articole._btnprint_click(cls_catalog_articole.java:401)
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:625)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
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:94)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
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)
Can anybody help me what is wrong ?
Thank you.

B4X:
Sub CreatePDFTable(title As String,tv As TableView)
    Dim PDFjetPDF1 As PDFjetPDF=CreateBasePDFDocument(title)
 
    Dim PDFPage As PDFjetPage
    PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

    Dim PDFFont1 As PDFjetFont
    PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD)
    PDFFont1.SetSize(7)
 
    Dim PDFFont2 As PDFjetFont
    PDFFont2.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA)
    PDFFont2.SetSize(7)
 
    Dim PDFFont3 As PDFjetFont
    PDFFont3.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD_OBLIQUE)
    PDFFont3.SetSize(7)
 
    Dim PDFTable As PDFjetTable
    PDFTable.Initialize
    Dim TableData1 As PDFjetTableData
    TableData1.Initialize
    Dim i As Int
    Dim PDFCell As PDFjetCell
    Dim hRow As PDFjetCellList
    Dim Row As PDFjetCellList
    Dim h(tv.ColumnsCount) As String
    For c=0 To tv.ColumnsCount-1
        h(c)=tv.GetColumnHeader(c)
    Next
    hRow.Initialize
    For x=0 To h.Length-1
        PDFCell.Initialize2(PDFFont1,h(x) )
        PDFCell.SetBottomPadding(2)
        PDFCell.SetLeftPadding(2)
        PDFCell.SetRightPadding(2)
        PDFCell.SetTopPadding(2)
        hRow.Add(PDFCell)
        Log(hRow)
    Next
    TableData1.AddRow(hRow)
    For i=0 To tv.Items.Size-1
        Row.Initialize
        Dim rowElementsList() As String=tv.Items.Get(i)
            For r=0 To rowElementsList.Length-1          
            PDFCell.Initialize2(PDFFont2,rowElementsList(r) )
            PDFCell.SetBottomPadding(2)
            PDFCell.SetLeftPadding(2)
            PDFCell.SetRightPadding(2)
            PDFCell.SetTopPadding(2)
            Row.Add(PDFCell)
        Next
        TableData1.AddRow(Row)
    Next
    PDFTable.SetData2(TableData1, PDFTable.DATA_HAS_2_HEADER_ROWS)
    PDFTable.SetCellBordersWidth(0.2)
    PDFTable.SetPosition(10, 30)
    'PDFTable.SetTextColorInRow(6, PDFjetConstants1.Color.blue)
    PDFTable.AutoAdjustColumnWidths
'    PDFTable.SetColumnWidth(0, 60)
'    PDFTable.RightAlignNumbers
 
    '    here you can see two different ways to render a table that will span more than one page in the PDF document
    '    comment/uncomment each block of code and you'll see the same results
 
'    Dim NumberOfPages As Int=PDFTable.GetNumberOfPages(PDFPage)
'    For i=1 To NumberOfPages
'        PDFTable.DrawOn(PDFPage)
'        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)
'    Next
 
    Do While PDFTable.HasMoreData
        PDFTable.DrawOn(PDFPage)
        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)
    Loop
 
    PDFjetPDF1.Close
End Sub
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Change this
Dim rowElementsList() As String

to

Dim rowElementsList() As Object

The ide has different pipes (and rules) if you have breakpoints on the code.
 

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
It's possible starting from an existing pdf and modify it?
Why i have this error?
B4X:
Dim PDF As PDFjetPDF
    PDF.Initialize3
    PDF.SetAuthor("xxx")
    PDF.SetSubject("xxx")
    PDF.SetTitle("xxx")
    Dim in As InputStream = File.OpenInput(File.DirApp, "my.pdf")
    PDF.Read(in) ' <<< Error
    in.Close
java.lang.NoSuchMethodError: uk.co.martinpearman.b4j.pdfjet.B4APDF.read(Ljava/io/InputStream;)Ljava/util/Map;
.....
.....

Thanks

'Moved to B4J Questions
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Mac Osx error
This library is for osx 10.10.1 Yosemite!!

View attachment 31226

View attachment 31228

This Library work in fantastic way also in Mac ( Tried Mac with Catalina 10.15.6 )

1598591879252.png


Thank you Martin. Great work
 
Top