B4A Library PDFjetB4A

PDFjetB4A is a PDF document authoring library for B4A

PDFjetB4A 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 both free evaluation and paid for licenses.
PDFjetB4A can be used with both the free evaluation and paid for licenses.
The free license version used to be feature limited, it looks as though the latest free license version contains all the features of the paid for license but i have not checked that.
PDFjetB4A wraps all available features of the paid for license version - if any of those features are not available in the free license version then the features will show in the B4A 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 PDFjetB4A 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 to find out about all available versions of PDFjet for Java.

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

Now download the attached PDFjetB4A library files and copy these to your B4A additional library folder.
Your B4A additional libraries folder should now contain: PDFjetB4A.jar, PDFjetB4A.xml and PDFjet.jar.
PDFjetB4A.html is for reference only - you don't need to copy this file to your additional libraries folder.
If you upgrade from the free version to the paid for version you just need to overwrite the 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 B4A 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.

I have also created a B4J version of this library, see the jPDFjet thread.
Both B4A and B4J versions share the same syntax.

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 a B4J project and this B4J project is available in the jPDFjet thread.
(I've not had time to create a B4A demo project).

Library files attached.

Martin.
 

Attachments

  • PDFjetB4A-library-files-v1.10.zip
    78.8 KB · Views: 1,496
Last edited:

warwound

Expert
Licensed User
Longtime User
Available versions of PDFjet for Java
My original post was not quite correct about the available versions of the PDFjet for Java library.
There are three available versions:
  • The free Open Source Edition of PDFjet for Java available at: http://pdfjet.com/os/download.html
    The Open Source Edition is not as feature packed as the other two versions, the available features are listed here: http://pdfjet.com/os/edition.html.
    The Open Source Edition download contains java source code only - it does not contain a ready compiled PDFjet.jar library file.
  • The free evaluation version of PDFjet for Java available at: http://pdfjet.com/java/download.html
    The evaluation version has all of the features of the paid for version.
    All PDF documents produced using the evaluation version will be watermarked with a notice saying that they have been produced using an evaluation version of PDFjet.
    The evaluation version download contains a ready compiled PDFjet.jar library file and no java source code.
  • The paid for version of PDFjet for Java available at: http://pdfjet.com/java/buy.html
    The paid for version download contains a ready compiled PDFjet.jar library file and no java source code.
In order to use the B4A library you need a compiled PDFjet.jar library file.
That library file is included in the evaluation and paid for version downloads but not in the Open Source Edition download.
If you plan to use the Open Source Edition you can either:
  • Download the Open Source Edition and compile the java source code into a PDFjet.jar library file:
    • You could use the Simple Library Compiler
    • You could create an Eclipse project or a standard java project using your favorite IDE.
  • Download my ready compiled Open Source Edition PDFjet.jar.
The download pages for each version contain the terms and conditions of use for each version.
And my Open Source Edition PDFjet.jar download contains a couple of license files that apply to the Open Source Edition.

Martin.
 
Last edited:

Jaames

Active Member
Licensed User
Longtime User
Hi

First of all, thank you very much for this lib. Fantastic work. thumbs UP! :)

Since you did not provide us with B4A example, I tried to compile B4J example with Basic4Android.
I copied xml and jar file (PDFjetB4A.xml and PDFjetB4A.jar) to the additional libs folder along with PDFjet.jar file,
and I have this error:

It force close the compiled app at this line : "PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)"

the "LastSelectedDir" is declared in Activity_Create as LastSelectedDir = File.DirRootExternal

B4X:
Sub CreateBasePDFDocument As PDFjetPDF
    Dim PDFDestination As OutputStream
    PDFDestination = File.OpenOutput(LastSelectedDir, ExampleChooser.SelectedItem & ".pdf", False)
   
    PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
    PDFjetPDF1.SetAuthor("Martin Pearman")
    PDFjetPDF1.SetSubject("jPDFjet Examples")
    PDFjetPDF1.SetTitle(ExampleChooser.SelectedItem)
   
    Return PDFjetPDF1
End Sub

the error code is :

java.lang.NoClassDefFoundError: uk.co.martinpearman.b4a.pdfjet.B4APDF

Do You have any idea what could be wrong?

Thanks again.
 

warwound

Expert
Licensed User
Longtime User
@Jaames

Are you compiling using rapid debug mode?
If so can you try legacy debug mode, release or obfuscated modes?

If you're not using rapid debug mode then i'll look in more detail at the exception later.

Martin.
 

Jaames

Active Member
Licensed User
Longtime User
@Jaames

Are you compiling using rapid debug mode?
If so can you try legacy debug mode, release or obfuscated modes?

If you're not using rapid debug mode then i'll look in more detail at the exception later.

Martin.

I'm compiling in release mode and debugging with legacy debugger.
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, same problem here:

Cannot get methods of class: uk.co.martinpearman.b4a.pdfjet.PDFWrapper, disabling cache.

java.lang.RuntimeException: Method: Initialize not found in: uk.co.martinpearman.b4a.pdfjet.PDFWrapper

in the line:

B4X:
PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
 

thughesimsuk

Member
Licensed User
Longtime User
I have this library installed, Can someone post a working .b4a project file if possible? I'm sure it would help not only myself but all the users out there. I have great interest in trying to get this working.

Thanks in advance,

Tom
 

warwound

Expert
Licensed User
Longtime User
It seems as though the PDFjetB4A library will work with both the evaluation and paid for versions of PDFjet for Java but not with the Open Source Edition of PDFjet for Java.

The Open Source Edition of PDFjet for Java does not contain some classes that the evaluation and paid for versions contain.
I thought this wouldn't be a problem - i thought that any features that used these missing classes would fail but other methods that did not use these missing classes would still work.
That's not the case it seems :(

However nobody has reported this problem when using the Open Source Edition and the B4J jPDFjet library.
Surely if the missing classes are not a problem with B4J then they're not a problem with B4A?

Anyway - i have a couple of choices for a solution but cannot promise i'll have a fix uploaded for a few days.
(Currently enjoying a short holiday - be back home Thursday).

Martin.
 

warwound

Expert
Licensed User
Longtime User
I just tested jPDFjet (the B4J version of this library) and it works with the Open Source Edition of PDFjet.
The missing classes in the Open Source Edition are not a problem with B4J.

Until i get a fix uploaded i'd suggest that you download and use the evaluation version of PDFjet for Java.
That'll enable you to develop code - albeit your PDF documents will contain an 'evaluation watermark'.
And when i get the fix uploaded you can just switch back to the Open Source Edition and continuing developing.

Martin.
 

warwound

Expert
Licensed User
Longtime User
PDFjet Open Source Edition

I have fixed the problems with the Open Source Edition.
(I'd compiled the PDFjet.jar library file with java 7 compliance and that's not compatible with android, i re-compiled it using java 6 compliance and it works with the PDFjetB4A library.)

If you have already downloaded my Open Source Edition PDFjet.jar file then please delete it and download the new android compatible version: http://b4a.martinpearman.co.uk/pdfjet/Open-Source-PDFjet.jar.zip

Here's a summary of features available in the full/evaluation versions but not available in the Open Source Edition:

Objects not available:
  • BarCode2D
  • BarCode
  • Chart
  • Paragraph
  • PDFobj
  • TextColumn

Additionally:
  • PDFjetFont has no Initialize4 method.
  • PDFjetPDF has no methods:
    • AddObjects
    • GetPageObjects
    • Read

And a very simple B4A demo project is attached.
As i said previously, the B4J thread contains a very complete example that can be applied in B4A with a little copy/paste and minor modification.

Martin.
 

Attachments

  • PDFjet-SimpleExample.zip
    6.2 KB · Views: 1,143

Harris

Expert
Licensed User
Longtime User
Looks like a great replacement for the PDFWriter of current - and at only 300 bucks.
I can even use it on my web server.

SO, we shall have to buy our own full copy before we can have a full B4A wrapper that we shall compile ourselves?

Thanks Martin.
 

warwound

Expert
Licensed User
Longtime User
The b4a and b4j libraries will work with the paid for version of PDFjet for Java - tested here and it works fine.
If you buy the paid for version you'll receive a fully featured PDFjet.jar library file.
Just overwrite the open source or evaluation PDFjet.jar with your paid for PDFjet.jar and you'll have access to all features of the paid for version.

Martin.
 

warwound

Expert
Licensed User
Longtime User
PDFjet version 5.03 has been released

http://pdfjet.com/news.html

  • Performance improvements. PDFjet now uses less memory and produces smaller PDF files. For some types of PDFs the size reduction could be up to 15% - for others the difference is very small.
  • Improved the Chart class and added two new examples to show how to create bar charts.

As well as the above two updates the Point object has been updated:
  • GetDrawLineTo() method has been removed.
    The documentation for this method states:
    Returns the current value of the private DrawLineTo property.
  • SetDrawLineTo() method is now deprecated:
    Deprecated. Please use the SetStartOfPath method.
  • New methods:
    • GetTextColor
    • GetTextDirection
    • SetStartOfPath
    • SetTextColor
    • SetTextDirection

I've updated PDFjetB4A to version 1.10 and attached it to the first post in this thread.
I've also re-compiled the Open Source Edition PDFjet.jar.

If you have paid for PDFjet then be sure to contact pdfjet.com and ask them for a link to download the latest version.
If you are using the Open Source Edition then download my updated Open Source Edition PDFjet.jar.

Martin.
 

tucano2000

Active Member
Licensed User
Longtime User

johndb

Active Member
Licensed User
Longtime User
This is a very interesting library and thank you Warwound for all of your hard work to allow us B4A users access to its features. I notice that the maximum resolution of creating graphics is 72 dpi. Is this correct or is this definable? You would think that PDFJet would have allowed a resolution of at least 300 dpi for vector graphics.
 

warwound

Expert
Licensed User
Longtime User
@johndb

I don't quite understand the problem here...
Are you saying that PDFjet processes any images you add to a PDF document reducing their density to a maximum of 72dpi?

Can you upload a sample project that demonstrates the problem?

Martin.
 

johndb

Active Member
Licensed User
Longtime User
@johndb

I don't quite understand the problem here...
Are you saying that PDFjet processes any images you add to a PDF document reducing their density to a maximum of 72dpi?

Can you upload a sample project that demonstrates the problem?

Martin.

I should have been a little more specific as my comment was regarding vector graphic functions and not inserting images. The line, circle, .... and other methods use the "pt" 72dpi "x" and "y" coordinates which equates to 3 pixels/mm. This resolution is too course for producing vector based drawings.

UPDATE: I contacted PDFjet support and the maximum resolution of the drawing functions with their library is fixed 1/72" pixels. This means that the library would not be suitable for drawing high resolution drawings such as those produced by AutoCAD for example but if you are wanting rough vector style drawings then this package could do the job.
 
Last edited:

Ron Davey

Member
Licensed User
Longtime User
I purchased a copy of PDFJet and copied the PDFJet.jar file in my current libraries folder. I am getting the following error:

java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition

What am I doing wrong?

Thanks
 

warwound

Expert
Licensed User
Longtime User
@Ron Davey

Last time i used PDFjet was version 5.03, the latest version is 5.07:
http://pdfjet.com/news.html

I wonder if there been any changes made which make the latest version incompatible with the b4a library...
I've requested a copy of version 5.07 and i'll take a look as soon as i receive the new version.

Do you use B4J?
If so and you have time you could try the B4J PDFjet demo project.
See if that works or throws ClassNorFoundExceptions.
http://www.b4x.com/android/forum/threads/jpdfjet.37842/#content

Martin.
 
Top