Multi-page table with MBS DynaPDF

I’d like to create a multi-page PDF using MBS DynaPDF. The first page would have a graphic at the top, with the table starting immediately underneath. If the table has too many rows to fit on one page, I’d like it to continue on as many follow-on pages as necessary. The problem is that I’d like the graphic to appear on the first page only, so on the second and subsequent pages I want the table to start from the top of the page. The same as you’d get if you placed a graphic at the top of a Microsoft Word document, and then added a long table underneath.

I’ve looked through the examples that come with the plug-in, but haven’t found one that does this. The “DynaPDF Table Multi Page” example has a table which continues on extra pages as necessary depending on the number of rows in the table, but the distance from the top of the page to the top of the table is the same on page 2 and subsequent pages as it is on page 1. I also had a look at the example in the “Dynamic Table” folder, but it won’t compile for me under Xojo 2016 r2.1 - it reports a NilObjectException.

Any suggestions/pointers please?

did you see the invoice example coming with our plugins?

Where is the nil object exception?
Maybe the pdf template file is not found?

You can of course also change the example to start table on first page on a different position.

Thanks Christian. The “DynaPDF Table Multi Page” example I mentioned creates invoices for a (presumably) fictional company called “Der Supermarkt.de”. But for each invoice, the table starts at the same place on the page on the 2nd and subsequent pages as it does on the first page. Maybe there’s another invoice example I’ve missed?

I haven’t so far worked out how to get the plugin to do what I’m looking for, as per my Microsoft Word document analogy. My code for drawing the table is the following - it’s based on the examples:

do call table.DrawTable( 55.0, 380, 380) if table.HaveMore then call pdf.EndPage call pdf.Append table.SetPDF pdf else exit end if loop

If there are too many rows in the table, it does continue on another page, but not from the top of the page as I need it to do.


As for the NilObjectException in the example in the “Dynamic Table” folder, it’s in:

Sub AddAddress(pdf as DynaPDFMBS, record as Customer)

at the line

call table.SetCellText(rowNum, 0, pdf.ktaLeft, table.kcoCenter, Record.Company)

The PDF templates and the project file for the example are together in the same folder, as bundled with the plug-in. However, I’ve copied the whole Examples folder to the Desktop, and am opening the examples from there. Perhaps that’s the problem?

For table.DrawTable function you pass one parameter for y position on where table starts.
DrawTable(x,y,h)

there you define y position where it starts and how much space to use as maximum height.
You can change y as needed.

for the nil object exception, well it does not happen here.
Do you have a latest plugins with latest examples?

You get the chance to set the start position for each page

Something like this:

[code]
dim topofpage as double
topofpage = 100
availablespace = pageheight - topofpage

do
call table.DrawTable( leftmargin, topofpage , availablespace)

if table.HaveMore then

topofpage = 55
availablespace = pageheight - topofpage
end if

loop[/code]

Hah! Of course, the DrawTable method is called on each trip round the loop. A lesson for me on the pitfalls of copying and pasting code without taking time to look at how it works!

Thanks Christian for your quick response and help, and Jeff for the very clear example.


Christian - I downloaded a fresh copy of the plugin from your website. It looks like I already had the most up-to-date one though - modification date is 11/07/2016 at 14:21, and the file sizes are the same. I tried the freshly-downloaded example file from the “Dynamic Table” folder and got the same NilObjectException. I’m running Windows 10 64-bit and Xojo 2016 Release 2.1. Can run some more tests on it if you like, or we could just mark it down as a one-off anomaly?

Okay, on Windows the events are different.

So we need to add a check to render method to only do it there, when pdf is not nil:

[code]Sub render()
if pdf <> nil then

if MainWindow.CheckBox1.Value then
  
  pic = pdf.RenderPagePicture(page, 595*2, 842*2, pdf.kpsFitBest)
else
  pic = pdf.RenderPagePicture(page, 595, 842, pdf.kpsFitBest)
end if

end if
End Sub[/code]

Thanks again Christian - that tweak has made the example in the “Examples/DynaPDF/Dynamic Table” folder work.

Just as a heads-up - there’s another “Dynamic Table” folder at the path “Examples/DynaPDF/Tables/Dynamic Table”. That one doesn’t work even with the tweak you gave above. An older version of the same example, maybe?

the one in the Tables folder is the older project.
I fixed it and just put the fixed on in the DynaPDF folder, so we got two.
Please ignore the other one.

Great stuff - thanks.