B4J Library jPDFjet

jPDFjet is a PDF document authoring library for B4J

jPDFjet 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 Open Source, free evaluation and paid for licenses.
jPDFjet can be used with all three licenses.
The Open Source Edition is feature limited.
jPDFjet wraps all available features of the paid for license version - any features that are not available in the Open Source Edition will show in the B4J 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 jPDFjet 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 in this thread to find out about the available versions of PDFjet for Java.

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

Now download the attached jPDFjet library files and copy these to your B4J additional library folder.
Your B4J additional libraries folder should now contain: jPDFjet.jar, jPDFjet.xml and PDFjet.jar.
jPDFjet.html is for reference only - you don't need to copy this file to your additional libraries folder.

If you upgrade from the Open Source Edition or from the free version to the paid for version you just need to overwrite the Open Source Edition or 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 B4J 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.

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 B4J and the attached B4J demo project contains those converted examples.

Note that i have also created a B4A version of this library and shall upload the B4A version shortly.
Both B4A and B4J versions share the same syntax.

Library files and demo project attached.

Martin.
 

Attachments

  • jPDFjet-demo-project.zip
    67 KB · Views: 3,475
  • jPDFjet-library_files-v1.10.zip
    78.9 KB · Views: 4,261
Last edited:

Phayao

Active Member
Licensed User
Longtime User
Hello, another stupid question .....

I run the jpdfdemo from the first post, using the libraries from this post also.
After choosing "Table" i get the following error:

Program started.
lastdir: D:\www\B4J\PDFJET~1\Objects
file: Table.pdf
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.pdfjet.Font.setSize(F)V
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: com.pdfjet.Font.setSize(F)V
at uk.co.martinpearman.b4j.pdfjet.FontWrapper.SetSize(FontWrapper.java:98)
at uk.co.martinpearman.b4j.pdfjetexample.main._createpdftable(main.java:1163)
at uk.co.martinpearman.b4j.pdfjetexample.main._createbutton_action(main.java:229)
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:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:606)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:225)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
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:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 9 more

This error appeared suddenly (?) also in my own program using the jPDF library ...
Maybe anyone had the same problem and can give some advice - much appreciated,

Thank you, Chris
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
It could be 2 issues.

Warwound stated that some methods are not available in the open source jar.

The other one is that you updated your pdfjet jar to the most updated version from their webpage and this wrapper is outdated.

In the second post of this thread you will find a compiled version of the open source PDFjet.jar. Replace it for the one you have in your folder, if that does not solve the issue avoid using the font.setsize method.
 

jahswant

Well-Known Member
Licensed User
Longtime User
@alienhunter

When a PDF table spans more than one page the library seems to not handle table header rows properly.
Multi-line table headers seem to cause the library to fail to properly count the number of pages required to display a table.
Is there a workaround for this issue ?
Me too i'm getting this...
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Is there a workaround for this issue ?
Me too i'm getting this...

This is not a problem for the wrapper, but for the API, the PDFJet team are very active with their product, i contacted them 3 weeks ago and they answered me within hours, may be you can reach them for a solution.
 

Don Oso

Active Member
Licensed User
Longtime User
I cannot remember if i compiled this version my self, you should try it.
mmmm same problem im getting same error with your .jar

Waiting for debugger to connect...
Program started.
java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
at uk.co.martinpearman.b4j.pdfjet.TextLineWrapper.SetPosition(TextLineWrapper.java:106)
at uk.co.martinpearman.b4j.pdfjetexample.main._createpdfbasicexample(main.java:272)
at uk.co.martinpearman.b4j.pdfjetexample.main._createbutton_action(main.java:196)
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:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
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:93)
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)
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
 

ajk

Active Member
Licensed User
Longtime User
It works correctly as below with European code set
B4X:
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(File.DirAssets,"droid-serif.regular.ttf")
    PDFFont1.Initialize3 (PDFjetPDF1, InputStream1)
 

mshafiee110

Active Member
Licensed User
Longtime User
Hi dear @warwound, can you update this great lib ?tnx
 

neuronio

Member
Licensed User
Longtime User
mmmm same problem im getting same error with your .jar

Waiting for debugger to connect...
Program started.
java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
at uk.co.martinpearman.b4j.pdfjet.TextLineWrapper.SetPosition(TextLineWrapper.java:106)
at uk.co.martinpearman.b4j.pdfjetexample.main._createpdfbasicexample(main.java:272)
at uk.co.martinpearman.b4j.pdfjetexample.main._createbutton_action(main.java:196)
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:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
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:93)
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)
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)

I have the same error.
 

neuronio

Member
Licensed User
Longtime User
Thx @Don Oso!!! :)
Unfortunately it did not work ...

I tried to compile the PDFjet (Open) and create the library with the SLC, but it presented error in both.
Also tried running everything with a clean VM and with JDK-8u151, made the same error.

B4X:
Waiting for debugger to connect...
Program started.
java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
    at uk.co.martinpearman.b4j.pdfjet.TextLineWrapper.SetPosition(TextLineWrapper.java:106)
    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.runVoidMethod(Shell.java:657)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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:93)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
    at uk.co.martinpearman.b4j.pdfjetexample.main._createpdfbasicexample(main.java:242)
    at uk.co.martinpearman.b4j.pdfjetexample.main._createbutton_action(main.java:196)
    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:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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:93)
    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)
Error occurred on line: 130
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
    at uk.co.martinpearman.b4j.pdfjetexample.main._createpdfbasicexample(main.java:242)
    at uk.co.martinpearman.b4j.pdfjetexample.main._createbutton_action(main.java:196)
    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:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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:93)
    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)
Caused by: java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)V
    at uk.co.martinpearman.b4j.pdfjet.TextLineWrapper.SetPosition(TextLineWrapper.java:106)
    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.runVoidMethod(Shell.java:657)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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)
    ... 25 more
An error occurred: 
(Line: 131) PDFTextLine.SetText("This is the PDFjetTextLine o
java.lang.Exception: array not expected...


Use this file, copy the jar file to your b4j library directory.

Regards
 

DonManfred

Expert
Licensed User
Longtime User
Program started.
java.lang.NoSuchMethodError: com.pdfjet.TextLine.setPosition(FF)

Are you sure you have a FULL Version (paid license) of pdfjet?

The Open Source Edition is feature limited.
jPDFjet wraps all available features of the paid for license version - any features that are not available in the Open Source Edition will show in the B4J IDE but not be available for use.
Trying to use a feature that is not available is like to raise a ClassNotFound exception.

So it sounds like this is maybe only available in the paid version of pdfjet....
 

Cassie

Member
Licensed User
Longtime User
Hi Guys,

Anyone could, I have recently a working PDFjet.jar but I have accidentally overwrite it and gives me an error java.lang.NoSuchMethodError: com.pdfjet.Font.setSize(F)V
blablabla...

Thanks in advance.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
The problem between the pdfJet and this library is that at one point in time the creators decided that to use float instead of double, that is why there are to many errors. not because it is or it is not free or paid.

so because even paying will not solve the issue, the best way to overcome the error is brewing your own library, it is not as hard as you think. i remember doing it with inline java. something like this;


B4X:
Sub Class_Globals
    Private PDFobject As Object
    Private Output As OutputStream

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(path As String, name As String)
    Output = File.OpenOutput(path,name,False)
    PDFobject = init(Output)   

End Sub

private Sub init(fos As OutputStream) As Object
    Return inline.RunMethod("init",Array(fos))
End Sub

Public Sub Flush 
    inline.RunMethod("Flush",Array(PDFobject))
    Output.Close
End Sub

public Sub Flush2
    Output.Close
End Sub

public Sub addPage(pageOB As Page)
        inline.RunMethod("addPage",Array(PDFobject,pageOB.PageOb))
End Sub

public Sub PDFOb As Object
    Return PDFobject
End Sub

private Sub inline As JavaObject
Return Me
End Sub

#if Java

import java.io.*;
import java.util.*;

import com.pdfjet.*;

    static public PDF init(OutputStream fos) throws Exception { 
        PDF pdfob = new PDF(fos);
        return pdfob;
    }
   
    static public void Flush(PDF pdf) throws Exception { 
        pdf.flush();
    }
   
    static public void addPage(PDF pdf, Page page) throws Exception  { 
        pdf.addPage(page);
    }
   
#end if

there are other classes to do it: page and fonts mainly. Page has all the methods to write to the pdf canvas such as string, lines and images.

hope this helps anyone.

i am by no means java expert, not even a newbie, i have never been able to compile a eclipse project and even then brewing my own library was not difficult.
 

Cassie

Member
Licensed User
Longtime User
The problem between the pdfJet and this library is that at one point in time the creators decided that to use float instead of double, that is why there are to many errors. not because it is or it is not free or paid.

so because even paying will not solve the issue, the best way to overcome the error is brewing your own library, it is not as hard as you think. i remember doing it with inline java. something like this;


B4X:
Sub Class_Globals
    Private PDFobject As Object
    Private Output As OutputStream

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(path As String, name As String)
    Output = File.OpenOutput(path,name,False)
    PDFobject = init(Output)  

End Sub

private Sub init(fos As OutputStream) As Object
    Return inline.RunMethod("init",Array(fos))
End Sub

Public Sub Flush
    inline.RunMethod("Flush",Array(PDFobject))
    Output.Close
End Sub

public Sub Flush2
    Output.Close
End Sub

public Sub addPage(pageOB As Page)
        inline.RunMethod("addPage",Array(PDFobject,pageOB.PageOb))
End Sub

public Sub PDFOb As Object
    Return PDFobject
End Sub

private Sub inline As JavaObject
Return Me
End Sub

#if Java

import java.io.*;
import java.util.*;

import com.pdfjet.*;

    static public PDF init(OutputStream fos) throws Exception {
        PDF pdfob = new PDF(fos);
        return pdfob;
    }
  
    static public void Flush(PDF pdf) throws Exception {
        pdf.flush();
    }
  
    static public void addPage(PDF pdf, Page page) throws Exception  {
        pdf.addPage(page);
    }
  
#end if

there are other classes to do it: page and fonts mainly. Page has all the methods to write to the pdf canvas such as string, lines and images.

hope this helps anyone.

i am by no means java expert, not even a newbie, i have never been able to compile a eclipse project and even then brewing my own library was not difficult.

Hi Enrique,

Thanks for the response. Can you explain how does it works.

Thanks in advance.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Yes! it is not difficult!

with the code above you can create an instance of the pdf object that holds the pages and the fonts objects.

another example is to create the font object

B4X:
Dim FontObject as object = inline.RunMethod("init",Array(PDFOB,Name.ToUpperCase,size)) 'Here you pass the object created in the class i above

private Sub inline As JavaObject
Return Me
End Sub

#if Java
import java.io.*;
import java.util.*;
import com.pdfjet.*;

    static public Font init(PDF pdf,String fontName, double fontSize) throws Exception { 
        Font font = new Font(pdf,CoreFont.valueOf(fontName));
        font.setSize(fontSize);
        return font;
    }

#end if

The trick is to read the javadocs, you can find this javadocs inside the downloaded zip in their webpage
http://pdfjet.com/os/download.html

the one i created in the example above is the first constructor.

i think you can oversimplify everything by calling javaobject instead of inline java, i was young and naive 2 years ago when i worked with it (since then the warwound library gave problems)
upload_2018-1-20_13-6-13.png
 

Omar Moreno

Member
Licensed User
Longtime User
The problem between the pdfJet and this library is that at one point in time the creators decided that to use float instead of double, that is why there are to many errors. not because it is or it is not free or paid.

so because even paying will not solve the issue, the best way to overcome the error is brewing your own library, it is not as hard as you think. i remember doing it with inline java. something like this;


B4X:
Sub Class_Globals
    Private PDFobject As Object
    Private Output As OutputStream

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(path As String, name As String)
    Output = File.OpenOutput(path,name,False)
    PDFobject = init(Output)  

End Sub

private Sub init(fos As OutputStream) As Object
    Return inline.RunMethod("init",Array(fos))
End Sub

Public Sub Flush
    inline.RunMethod("Flush",Array(PDFobject))
    Output.Close
End Sub

public Sub Flush2
    Output.Close
End Sub

public Sub addPage(pageOB As Page)
        inline.RunMethod("addPage",Array(PDFobject,pageOB.PageOb))
End Sub

public Sub PDFOb As Object
    Return PDFobject
End Sub

private Sub inline As JavaObject
Return Me
End Sub

#if Java

import java.io.*;
import java.util.*;

import com.pdfjet.*;

    static public PDF init(OutputStream fos) throws Exception {
        PDF pdfob = new PDF(fos);
        return pdfob;
    }
  
    static public void Flush(PDF pdf) throws Exception {
        pdf.flush();
    }
  
    static public void addPage(PDF pdf, Page page) throws Exception  {
        pdf.addPage(page);
    }
  
#end if

there are other classes to do it: page and fonts mainly. Page has all the methods to write to the pdf canvas such as string, lines and images.

hope this helps anyone.

i am by no means java expert, not even a newbie, i have never been able to compile a eclipse project and even then brewing my own library was not difficult.


Excuse my English (Translated with Google).

Greetings Enrique.

I have tested with version 1.10 of JPdfJet, but it does not work to generate bar codes.

You could upload a simple example in ZIP to see the operation of this library, since the IDE gives me an error in this line "public Sub addPage (pageOB As Page)".

I have used the PDFJet library creating a Java file which I then convert with the Simple Library Compiler utility, something similar to a Wrapper and it works, but since I do not have much experience in Java it is difficult for me to create a wrapper to generate any PDF document and not one for each PDF.

Thanks for the help you can give me.
 
Top