B4J Library PD_PDFBox

A B4J wrapper for Apache PDFBox 2.0.37 to generate PDF documents.

Key Features:
  • Percentage-based layout: All positions and dimensions expressed as % of the page
  • Text & paragraphs: Persian/Arabic shaping, auto line-wrap and page-break
  • Tables: Simple CreateTable → AddRow → EndTable API with auto-repeating headers
  • Graphics: Lines, rectangles, and images
  • Page numbering: Auto footer with customizable format, size, and position
  • Fonts: System fonts (Windows) or custom .ttf files (e.g. Vazir)
  • Printing: Direct-to-printer support
  • Chainable layout: Every draw method returns the next Y position in %

v1.1
AddRowAligned(String[] values, String hAlign)
AddRowAlignedCells(String[] values, String[] hAligns)
AddRowImage(String[] texts, String imagePath, int imageCol, double rowHeightPct)
AutoWrap Text for AddText
AutoWrap Text in Tables
Fix AddParagraph Line Space
bug fix
Sample updated.

v1.2
new AddRow method// AddRow(String[] values, String[] hAligns, String[] colors)
removed method : AddRowAligned,AddRowAlignedCells
added change color of the text in the columns

B4X:
Dim pdf As PD_PDFBox
pdf.Initialize
pdf.SetCustomFont("Vazir-Light.ttf", "Vazir-Bold.ttf")
pdf.AddPage("A4", False)
y = pdf.AddText("Hello world!", 10, 5, 80, 5, 14, "#000000", "RIGHT", "MIDDLE", True)
y = y+1
y = pdf.AddText("Hello world 2 !", 10, y, 80, 5, 14, "#000000", "RIGHT", "MIDDLE", True)
pdf.Save(File.DirApp, "test.pdf")

need jars - copy to b4j library folder : {"commons-logging-1.3.6.jar", "fontbox-2.0.37.jar", "icu4j-60.2.jar", "pdfbox-2.0.37.jar"}

Download jar files >> Download
 

Attachments

Last edited:
Please test the library and report any bugs you find here so we can fix them together. Also, if you need any specific features that are not currently available in the library, please let us know.
 
Just sent a access request
 
i clicked on the DOWNLOAD link in the post (for all files).
Google came up and presented a window to gain access
1792174426605.png
 
Hi behnam_tr you’ve done a great job.

I've two wishes :
one : the alignment of rows on every cell (description at left, amount at right, row number at center etc.)
two : it's possible to add an image at rows ?

Thanks in advice
 
Hi behnam_tr you’ve done a great job.

I've two wishes :
one : the alignment of rows on every cell (description at left, amount at right, row number at center etc.)
two : it's possible to add an image at rows ?

Thanks in advice
Thank you for your attention.
It will be added in the next update.
 
Very great job mr Behnam_tr the best lib for PDF creation.

But last wish ...

The colour of the text in the columns must be different from the colour of the rows because if i want the black background of the columns i want the white colour for the text of the columns but not for the text of the rows

Thanks
 
Hi Behnam_tr after a long test i found this problem there are three addrows but is necessary to have one addrow command with all features
the addrow depend to createtable and now is impossible to have all features in the table rows.

Thank for your work and patience
 
Hi Behnam_tr after a long test i found this problem there are three addrows but is necessary to have one addrow command with all features
the addrow depend to createtable and now is impossible to have all features in the table rows.

Thank for your work and patience
The suggestion has been received. I'm waiting for feedback from the other members so we can implement all the changes at once.
 
It's right thanks
v1.2
B4X:
 AddRow(String[] values, String[] hAligns, String[] colors)

1.pdf.AddRow(Array As String("behnam", "tehran", "10000"), Null, Null)

2.pdf.AddRow(Array As String("behnam", "tehran", "10000"), Array As String("CENTER"), Null)

3.pdf.AddRow(Array As String("behnam", "tehran", "10000"), Array As String("CENTER"), Array As String("#0B8537"))

4.pdf.AddRow(Array As String("behnam", "tehran", "10000"),  _
Array As String("CENTER","RIGHT","LEFT"), _
Array As String("#0B8537","#E8891A","#BD3988"))
 
Last edited:
Hi, behnam_tr i've tested the v. 1.2 and i find this little error with alignment RIGHT

B4X:
pdf.AddPage("A4", False)
y = 5
    
pdf.CreateTable(Array As String("Product", "Description", "Price"),Array As Double(30, 40, 30),5, y, 90, 4, 10,"#BF360C", "#CCCCCC", "#FFFFFF", "LEFT", "MIDDLE")   
pdf.AddRow(Array As String("Monitor 27 inch", "Electronics", "$549"),Array As String("LEFT", "LEFT", "RIGHT"),Array As String("#000000","#000000","#FF0000"))

y = pdf.EndTable

1792762506303.png

otherwise with LEFT

1792762588079.png

and CENTER

1792762641089.png


don't forget the possibility to add image at row and if you want in column too.

Yes i'm a troublemaker !! Sorry

Thanks in advice
 
Hi, behnam_tr i've tested the v. 1.2 and i find this little error with alignment RIGHT

B4X:
pdf.AddPage("A4", False)
y = 5
  
pdf.CreateTable(Array As String("Product", "Description", "Price"),Array As Double(30, 40, 30),5, y, 90, 4, 10,"#BF360C", "#CCCCCC", "#FFFFFF", "LEFT", "MIDDLE") 
pdf.AddRow(Array As String("Monitor 27 inch", "Electronics", "$549"),Array As String("LEFT", "LEFT", "RIGHT"),Array As String("#000000","#000000","#FF0000"))

y = pdf.EndTable

View attachment 174421
otherwise with LEFT

View attachment 174422
and CENTER

View attachment 174423

don't forget the possibility to add image at row and if you want in column too.

Yes i'm a troublemaker !! Sorry

Thanks in advice

The problem is with your code. The total column widths plus the left offset exceed 100%. >> is 105%

fixed :
B4X:
Array As Double(30, 30, 30)
 
Back
Top