Hello,

Here are 3 classes :
- PdfCreator : create PDF
- PDFViewer : render PDF
- clsFormPDF : form to preview PDF (Page navigation, Zoom, Print, Save)

PdfCreator and PDFViewer wraps PDFBox
You have to download pdfbox-app-2.0.20.jar and copy it in the additional folder
You have to download icu4j-67_1.jar and copy it in the additional folder for right to left and connected arabic characters
B4X:
    #AdditionalJar: pdfbox-app-2.0.20.jar
    #AdditionalJar: icu4j-67_1.jar

For right to left and connected arabic characters, you need to uses the "bidi" method to buld your string
B4X:
    s=pdfcreator.bidi("صباحا")

The zip contains a small project which show how to create PDF and preview them
  • The fist is very simple, just few lines of text
  • The second is a long list with image, table, page footer, text color, background color....
  • The third use differents standard fonts and load a font from a file and display arabic characters
1592157008136.png

1592157047929.png


1592159743160.png

1593780330305.png


To create a PDF :
  1. Create an instance of pdfCreator and initialize it
  2. Create page
  3. Create content
  4. Write on the content (text, image, rect)
  5. Close content
  6. Add page to PDF
  7. repeat 2 to 6
  8. write PDF to stream or file

spsp
 

Attachments

  • b4JPDF.zip
    162.5 KB · Views: 607
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Can you create a pdf from a B4J layouts the same way it is done with JavaFX8
This wrapper is able to create PDF Acroforms (and more)
 

TomDuncan

Active Member
Licensed User
Longtime User
Can this be used to print not only lines of text but
Multiple lines with CRLF separated fields.
Tom
 

TomDuncan

Active Member
Licensed User
Longtime User
Did a bit of work myself and came with this.

b4j:
'draw multline
public Sub drawMultiText(acontent As JavaObject,afont As JavaObject,asize As Float,aleft As Float,atop As Float,aLine As Float,atext() As String) As Float
    For i = 0 To atext.Length-1
        Dim txt As String = atext(i)
        drawText(acontent,afont,asize,aleft,atop,txt)
        atop = atop - aLine
    Next
    Return atop
End Sub
 

spsp

Active Member
Licensed User
Longtime User
Any example to open an existent pdf?
Hi, this library can't open existing PDF.

But the PDFBox which is used behind contains such methods. You have to look in that direction.

spsp
 
Top