B4J Library jPDFjet

warwound

Expert
Licensed User
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

Last edited:

warwound

Expert
Licensed 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 B4J 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:

warwound

Expert
Licensed User
PDFjet Open Source Edition updated

Fixing a problem with the B4A version of this library i have had to re-compile my Open Source Edition PDFjet.jar library file.

If you have already downloaded my Open Source Edition PDFjet.jar library file then you have a version that is not compatible with android.
That means you cannot use that downloaded version for both B4A and B4J - it will only work with B4J.

If you download the updated version of my Open Source Edition PDFjet.jar library then you will have a version that can be used with both B4A and B4J - the new version is android compatible.

You can download my Open Source Edition PDFjet.jar library from: http://b4j.martinpearman.co.uk/jpdfjet/Open-Source-PDFjet.jar.zip.

(The library file available at http://b4j.martinpearman.co.uk/jpdfjet/Open-Source-PDFjet.jar.zip is the same as the library file available at http://b4a.martinpearman.co.uk/pdfjet/Open-Source-PDFjet.jar.zip)

Martin.
 

warwound

Expert
Licensed 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 jPDFjet 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.
 

BPak

Active Member
Licensed User
Thank you for this Library.

I needed to do Reports in some of my projects and PDF turns out to be ideal for my use.

pb1.PNG
 

alienhunter

Active Member
Licensed User
Thanks works very nice

the only thing i do not quite understand is
B4X:
Do While PDFTable.HasMoreData
it is always creating a empty page even if the table does not need one
any clue why ?

thanks AH



pdf.jpg
 

warwound

Expert
Licensed 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.
 

alienhunter

Active Member
Licensed 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.
Thanks ,
i wish i had more time to learn this library creation how to , but anyway it works very good
thanks again for your time
 

ivanomonti

Well-Known Member
Licensed User
Hi,
multiline text is not considered, all I end up outside the page, how can I solve this problem, thanks

B4X:
' open print txt
Sub bt8_MouseClicked (EventData As MouseEvent)
   
    DateTime.DateFormat = "dd/MM/yyyy hh:mm:ss"
   
    Dim s As String 
    s = "SimpleEdit v1" & Chr(10) & _
        "By Ivano Monti" & Chr(10) & _
        "Date Print PDF (Portable Document Format) " & DateTime.Date(DateTime.Now) & Chr(10) & Chr(10) & _
        "Text Original" & Chr(10) & _
        tx1.Text & Chr(10) & _
        "Text Translate" & Chr(10) & _
        tx2.Text & Chr(10) & Chr(10)
    Try
        Dim PDFjetPDF1 As PDFjetPDF = CreateBasePDFDocument
        Dim PDFPage As PDFjetPage
        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_LANDSCAPE)

        Dim PDFFont1 As PDFjetFont
        PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.TIMES_ROMAN)
   
        Dim PDFTextLine As PDFjetTextLine
        PDFTextLine.Initialize(PDFFont1)
        PDFTextLine.SetPosition(10, 10+PDFFont1.GetHeight)
        PDFTextLine.SetText(s)
        PDFTextLine.DrawOn(PDFPage)
    Catch
   
    End Try
   
    PDFjetPDF1.Close
   
End Sub
B4X:
' create doc pdf
Sub CreateBasePDFDocument As PDFjetPDF
    Dim fileDestination As String = FileSelect.Replace(".txt",".pdf")
    Try
        Dim PDFDestination As OutputStream
        PDFDestination=File.OpenOutput(File.DirApp,fileDestination, False)
        PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
        PDFjetPDF1.SetAuthor("Poche Parole Possono Bastare")
        PDFjetPDF1.SetSubject("Print file: " & DateTime.Date(DateTime.Now))
        PDFjetPDF1.SetTitle(FileSelect)
        Return PDFjetPDF1
    Catch
        Dim msg As Msgboxes
        msg.Show("Error print save","Alert")
    End Try
   
End Sub
2015-01-15_144109.png
 

alienhunter

Active Member
Licensed User
Hi,
multiline text is not considered, all I end up outside the page, how can I solve this problem, thanks

B4X:
' open print txt
Sub bt8_MouseClicked (EventData As MouseEvent)

    DateTime.DateFormat = "dd/MM/yyyy hh:mm:ss"

    Dim s As String
    s = "SimpleEdit v1" & Chr(10) & _
        "By Ivano Monti" & Chr(10) & _
        "Date Print PDF (Portable Document Format) " & DateTime.Date(DateTime.Now) & Chr(10) & Chr(10) & _
        "Text Original" & Chr(10) & _
        tx1.Text & Chr(10) & _
        "Text Translate" & Chr(10) & _
        tx2.Text & Chr(10) & Chr(10)
    Try
        Dim PDFjetPDF1 As PDFjetPDF = CreateBasePDFDocument
        Dim PDFPage As PDFjetPage
        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_LANDSCAPE)

        Dim PDFFont1 As PDFjetFont
        PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.TIMES_ROMAN)

        Dim PDFTextLine As PDFjetTextLine
        PDFTextLine.Initialize(PDFFont1)
        PDFTextLine.SetPosition(10, 10+PDFFont1.GetHeight)
        PDFTextLine.SetText(s)
        PDFTextLine.DrawOn(PDFPage)
    Catch

    End Try

    PDFjetPDF1.Close

End Sub
B4X:
' create doc pdf
Sub CreateBasePDFDocument As PDFjetPDF
    Dim fileDestination As String = FileSelect.Replace(".txt",".pdf")
    Try
        Dim PDFDestination As OutputStream
        PDFDestination=File.OpenOutput(File.DirApp,fileDestination, False)
        PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
        PDFjetPDF1.SetAuthor("Poche Parole Possono Bastare")
        PDFjetPDF1.SetSubject("Print file: " & DateTime.Date(DateTime.Now))
        PDFjetPDF1.SetTitle(FileSelect)
        Return PDFjetPDF1
    Catch
        Dim msg As Msgboxes
        msg.Show("Error print save","Alert")
    End Try






End Sub
View attachment 31212



hi i am counting the characters that i want to write in the line with 1 loop
when i am at work i will post the code
had the same problem
 
Last edited:

ivanomonti

Well-Known Member
Licensed User
B4X:
Program started.
Exception in runnable
java.lang.RuntimeException: java.lang.Exception: Sub pdfjetpdf1_closecomplete was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at anywheresoftware.b4a.BA$3.run(BA.java:178)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:96)
    at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:384)
    at com.sun.glass.ui.EventLoop.enter(EventLoop.java:83)
    at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:523)
    at javafx.stage.Stage.showAndWait(Stage.java:397)
    at jfxtras.labs.dialogs.MonologFX.showDialog(MonologFX.java:370)
    at anywheresoftware.b4a.agraham.jmsgboxes.Msgboxes.show(Msgboxes.java:92)
    at anywheresoftware.b4a.agraham.jmsgboxes.Msgboxes.Show(Msgboxes.java:102)
    at b4j.example.main._bt8_mouseclicked(main.java:767)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:224)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:64)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
    at javafx.event.Event.fireEvent(Event.java:171)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3100)
    at javafx.scene.Scene$ClickGenerator.access$8600(Scene.java:3038)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3320)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3151)
    at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3106)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2248)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:530)
    at com.sun.glass.ui.View.notifyMouse(View.java:924)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.Exception: Sub pdfjetpdf1_closecomplete was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:100)
    ... 65 more
 

ivanomonti

Well-Known Member
Licensed User
Fixed missing close event

B4X:
Sub pdfjetpdf1_closecomplete(success As Boolean)
    Dim msg As Msgboxes
    msg.Show("pdf document created successfully","DPF Creator")
End Sub
 

alienhunter

Active Member
Licensed User
I could not solve problem multi-line text, can find a solution. thank you



B4X:
str=text.Text  ' load the whole text 
' i replace chr 
str=str.Replace(Chr(34) , "")
str=str.Replace(Chr(40) , "")
str=str.Replace(Chr(41) , "")
len=str.Length



Dim xxx As String
Dim lister As List
lister.Initialize


' here i check if str.lenght > 80 so i want only 80 char to be in a line 

If str.Length<80 Then
Dim chrr As Int =str.Length
Else
Dim chrr As Int =80
End If


If chrr > 79 Then
'
For i = 0 To len-1 Step 1
If i = 0 Then
xxx=""
xxx=(str.SubString2(0,chrr))
lister.Add(xxx)
End If

If len-z > chrr Then
If n = chrr Then
xxx=""
xxx=(str.SubString2(i,i+n))
lister.Add(xxx)
n=0
End If
End If


If len-z < chrr Then
If n= len-z Then
Log(len-z)
xxx=""
xxx=(str.SubString2(i,i+(len-z)))
lister.Add(xxx)
n=0
z=0
Log(z)
End If
End If


n=n+1 ' counters
z=z+1 ' counters
Next

Else

xxx=""
xxx=(str.SubString2(0,chrr))
lister.Add(xxx)

End If 


' here i write the list out in pdf 

For i = 0 To lister.Size-1
PDFWriter1.setFont(Fonts.SUBTYPE, Fonts.COURIER_BOLDOBLIQUE)
PDFWriter1.addRawContent("0 0 1 rg ")
PDFWriter1.addText(xer+5 , yer-20, 10,lister.Get(i))

Log(lister.Get(i))
xer=10 ' page x dim 
yer=yer-22 ' page y dim

If yer<50 Then
yer=760
PDFWriter1.newPage
End If
 

Phayao

Member
Licensed User
This library is really phantastic !
But i get a strange effect when i want to use a PDFTable and use wrap text (so long text will be automatically put in multiple lines in a cell with given width): when i put an image in a cell in the same row, this image is repeatedly shown for every linebreak of the text of the other cell !?!?
Someone had the same problem ?
Any help is appreciated,

Thanks, Chris
B4X:
Sub CreatePDFTable
    Dim PDFjetPDF1 As PDFjetPDF = CreateBasePDFDocument
   
    Dim PDFPage As PDFjetPage
    PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

    Dim PDFFont1 As PDFjetFont
    PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.TIMES_ROMAN)
    PDFFont1.SetSize(12)

    ' ----- get table data:
   
    Dim PDFTable As PDFjetTable
    PDFTable.Initialize

    Dim TableData1 As PDFjetTableData
    TableData1.Initialize
           
    Dim PDFCell As PDFjetCell
    Dim Row As PDFjetCellList
    Dim PDFImage As PDFjetImage

    Dim Column As String
    ' ----- get row of data:
    Dim cur As Cursor
    ' cur retrieves a list of items from a SQLite table,
    ' containing text and one image per row:
   
    For nrow = 0 To cur.RowCount-1
        cur.Position = nrow
        Row.Initialize
        For ncol = 0 To cur.ColumnCount - 1
            PDFCell.Initialize(PDFFont1)
            Column = cur.GetString2(ncol)
            If ncol = 3 Then  ' we have an IMAGE in this column
                ' Column contains the filename of the image:
                PDFImage.Initialize(PDFjetPDF1, File.OpenInput(picLocation, Column), PDFjetConstants1.ImageType.JPG)
                PDFImage.ScaleBy(0.2)
                PDFCell.SetImage(PDFImage)  ' <= HERE IS THE CRITICAL PART
            Else
                ' regular text:
                PDFCell.setText(Column) '    <= THIS WORKS FINE
            End If
            Row.Add(PDFCell)
        Next
        TableData1.AddRow(Row)
    Next
    cur.Close

    PDFTable.SetData2(TableData1, PDFTable.DATA_HAS_0_HEADER_ROWS)
    PDFTable.SetColumnWidth(0, 60)
    PDFTable.SetColumnWidth(1, 200)
    PDFTable.SetColumnWidth(2, 200)
    PDFTable.WrapAroundCellText ' <= THIS IS ESSENTIAL to wrap long text around in a cell

    Dim NumberOfPages As Int=PDFTable.GetNumberOfPages(PDFPage)
    For i=1 To NumberOfPages
        If i>1 Then PDFTable.SetPosition(70, 50)
        PDFTable.DrawOn(PDFPage)
        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)
    Next
 
Last edited:

jmon

Well-Known Member
Licensed User
This library is really phantastic !
But i get a strange effect when i want to use a PDFTable and use wrap text (so long text will be automatically put in multiple lines in a cell with given width): when i put an image in a cell in the same row, this image is repeatedly shown for every linebreak of the text of the other cell !?!?
Someone had the same problem ?
Any help is appreciated,

Thanks, Chris
B4X:
Sub CreatePDFTable
    Dim PDFjetPDF1 As PDFjetPDF = CreateBasePDFDocument
  
    Dim PDFPage As PDFjetPage
    PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

    Dim PDFFont1 As PDFjetFont
    PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.TIMES_ROMAN)
    PDFFont1.SetSize(12)

    ' ----- get table data:
  
    Dim PDFTable As PDFjetTable
    PDFTable.Initialize

    Dim TableData1 As PDFjetTableData
    TableData1.Initialize
          
    Dim PDFCell As PDFjetCell
    Dim Row As PDFjetCellList
    Dim PDFImage As PDFjetImage

    Dim Column As String
    ' ----- get row of data:
    Dim cur As Cursor
    ' cur retrieves a list of items from a SQLite table,
    ' containing text and one image per row:
  
    For nrow = 0 To cur.RowCount-1
        cur.Position = nrow
        Row.Initialize
        For ncol = 0 To cur.ColumnCount - 1
            PDFCell.Initialize(PDFFont1)
            Column = cur.GetString2(ncol)
            If ncol = 3 Then  ' we have an IMAGE in this column
                ' Column contains the filename of the image:
                PDFImage.Initialize(PDFjetPDF1, File.OpenInput(picLocation, Column), PDFjetConstants1.ImageType.JPG)
                PDFImage.ScaleBy(0.2)
                PDFCell.SetImage(PDFImage)  ' <= HERE IS THE CRITICAL PART
            Else
                ' regular text:
                PDFCell.setText(Column) '    <= THIS WORKS FINE
            End If
            Row.Add(PDFCell)
        Next
        TableData1.AddRow(Row)
    Next
    cur.Close

    PDFTable.SetData2(TableData1, PDFTable.DATA_HAS_0_HEADER_ROWS)
    PDFTable.SetColumnWidth(0, 60)
    PDFTable.SetColumnWidth(1, 200)
    PDFTable.SetColumnWidth(2, 200)
    PDFTable.WrapAroundCellText ' <= THIS IS ESSENTIAL to wrap long text around in a cell

    Dim NumberOfPages As Int=PDFTable.GetNumberOfPages(PDFPage)
    For i=1 To NumberOfPages
        If i>1 Then PDFTable.SetPosition(70, 50)
        PDFTable.DrawOn(PDFPage)
        PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)
    Next
Could you post a screen shot?
 

Phayao

Member
Licensed User
OK, here is a screenshot of an example - the image should appear just one time, but it is shown after each linebreak in the previous cells:


This won't happen without wraparoundcelltext command, but then the text lines go over the table cells and write into each other.

Thanks for any hint,

Chris
 
Top