B4J Question Create PDF in B4J

roger lovelock

Member
Licensed User
Longtime User
Hi,
In other environments I have found the best way of producing and distributing reports is often writing to a PDF and then letting the user open it with whatever is the default pdf reader on their system. Looking through the forum I see an example with printhtml being output via a pdf printer - but this introduces dependencies I'd rather avoid. Before I try the alternative below I thought I'd ask for advice!
My thought was that if the PDFWriter library from B4A was teamed with jFX.ShowExternalDocument I'd have my solution - so the question is - will the B4A PDFWriter library work with B4J.
As a second part to the question - I have a small PDF writing library written in java that I have used in some apps. It seems an obvious question - but I haven't found an answer yet - can you call routines in java library jars directly from a B4J program ( assuming the java library jar is in the B4J library folder I would guess).
Thanks for your advice.
Roger L
 

warwound

Expert
Licensed User
Longtime User
I have developed a wrapper library for PDFjet.
I have versions for both B4A and B4J.
My plan was to upload it to the forum, but there was an update to the java PDFjet library last month and my wrapper library now needs updating too.

Hopefully i'll get it updated and uploaded over the weekend.
I've uploaded a B4J demo app to here: http://b4j.martinpearman.co.uk/jpdfjet/jPDFjet_demo.jar.
To run it just use the command:
B4X:
java -jar jPDFjet_demo.jar

You could take your existing java PDF writing library and create a 'wrapper' library so that you can use it in B4A or B4J.
For more info have a look here: http://www.b4x.com/android/forum/threads/creating-libraries-for-basic4android.6810/.

Martin.
 
Last edited:
Upvote 0

roger lovelock

Member
Licensed User
Longtime User
At first look your demo app seems to give me all the functionality I need - I'll dig further. In the meantime I'm reading up on creating a wrapper library - not something I really think I want to do as my main motivation for looking at B4J is to get the advantages of the JVM without needing to get too heavily involved in Java. Thanks
 
Upvote 0

roger lovelock

Member
Licensed User
Longtime User
As I didn't get any indication on this forum whether the B4A PDFWriter library would work with B4J I thought I'd give it a go - it appears from my tests that the B4A library is not recognised by B4J - or else I am doing something very wrong (quite possible). So, my best bet at this stage, (as I am not interested in developing libraries myself) is to await the PDFjet wrapper library mentioned above. Look forward to trying it out!
Roger L
 
Upvote 0

roger lovelock

Member
Licensed User
Longtime User
Have written a little test program and got the library to work - looks excellent - except that I get a watermark across my pdf's saying they are produced with an evaluation copy of the pdf software. As I am a hobbyist writing software for a small non-profit organisation I'm not about to pay out for a full licence, and equally I don't want to run foul of any licensing limitations! No chance of producing a library from the open source version of pdfJet? Are there any other alternative libraries to produce pdf's available? The java one I have used in the past was a port of the PHP library FPDF (it is listed under the links on the FPDF site) - nice and small and very simple to use for basic report production.
Anyway - your library is a nice job - thanks!
 
Upvote 0

mtks

New Member
Licensed User
Longtime User
Hi all,

is it possible to print some (picture) Central Europe characters (CP1250) to PDF with PDFjet (open source version)?

thanks
m.
 

Attachments

  • pdfjet_char.png
    pdfjet_char.png
    24.3 KB · Views: 432
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
is it possible to print some (picture) Central Europe (CP1250) to PDF with PDFjet (open source version)?

There is a PDFjetCodePage constant value available:

B4X:
CP1250 As Int

And the PDFjetFont Initialize2 and Initialize4 methods accept that constant value:

B4X:
Initialize2 (PDFjetPDF As PDF, FontName As String, CodePage As Int)
Initialize2 is used to create an Asian Font.
FontName - known working values are: 'AdobeMingStd-Light' - Chinese (Traditional). 'STHeitiSC-Light' - Chinese (Simplified). 'KozMinProVI-Regular' - Japanese. 'AdobeMyungjoStd-Medium' - Korean.
CodePage - 1 of the PDFjetCodePage constants.

Initialize4 (PDFjetPDF As PDF, InputStream1 As InputStream, PDFjetCodePage As Int, Embed As Boolean)

But the Initialize4 method is not available with the Open Source version of PDFjet, so the Initialize2 method seems the only possible solution.
The documentation is pretty vague - though there is a java example available:
http://pdfjet.com/java/examples/example-04.html

The comments in the Open Source source code state:

FontName - the font name. Please see Example_04.
CodePage - the code page. Must be: CodePage.UNICODE

A Google search found this page: http://www.webbyexpert.com/pdfjet-encoding-options/.
Where someone is trying to use CP1250 with the Open Source PDFjet but there is no answer, only the question.

Sorry i can't be of more help :(.

Martin.
 
Upvote 0

mtks

New Member
Licensed User
Longtime User
I played with examples of PDFjet and found out, that Example_07 is able to print Central European (CP1250) characters with Open Source version of PDFjet. I tested only DejaVuLGCSerif.ttf.deflated font and it works!

In B4J the Initialize3 did the job:
B4X:
Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(File.DirAssets,"DejaVuLGCSerif.ttf.deflated")
    PDFFont1.Initialize3 (PDFjetPDF1, InputStream1)

I hope that this information can be usefull for Central Europe users.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
    Dim PDFFont1 As PDFjetFont, Cp As PDFjetCodePage
    PDFFont1.Initialize2(PDFjetPDF1, "AdobeMingStd-Light", Cp.UNICODE) 'Cp.UNICODE = 65001 = UTF8
  
    Dim PDFTextLine As PDFjetTextLine
    PDFTextLine.Initialize(PDFFont1)
    PDFTextLine.SetPosition(10, 10+PDFFont1.GetHeight)
    PDFTextLine.SetText("1. ЭТО СПАРТА!!!! ")
    PDFTextLine.DrawOn(PDFPage)

It works for national letters...but why no possibility to use any font :-(
 
Upvote 0
Top