B4J Library jPDFjet

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User

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/InputStreamLjava/util/Map;
.....
.....

Thanks

'Moved to B4J Questions
 
Last edited:

giannimaione

Well-Known Member
Licensed User
Longtime User
is there a update about jPDFjet library? (actualy version 1.10)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…