I always struggle with the y-coordinates in drawing
I am working on creating a PDFdocument. The doc is simple with a category title and a table below it, followed by another title and table, and so on
I set my yCoord at the top, add in the necessary spacing between before drawing the next piece. This document is different from others I’ve done previously as it has a series of tables. In the screenshot below, this doc has repeated tables with 7 rows + 1 header. It won’t always be a 7-row table. Could be more or less. I have managed to calculate the size of the table based on number of rows in order to display the next title + table. However, the problem I am running into is when the last table on the page goes onto the following page, my yCoord is confused and then starts the next page with a lot of whitespace on the current one
Here is how I handle going to the next page:
if yCoord > d.PageHeight - 50 then
g.NextPage
'reset yCoord
yCoord = 50
'start the next title + table combo and continue
Edit: Actually, nevermind my suggestion, I forgot PDFDocument comes with a bunch of controls for you to use. I always draw everything myself for precise control.
If I were to look at this issue, I would need the whole source code.
I made a slight change in the way I calculated the listbox height. Using the default 7 rows seems to display better, but if you enter something like “18” in the textbox, you’ll see the whitespace on page 2
Happy to report, I figured this out. The secret was in the Completed method of the PDFTableDataSource. This method provides the bottom x/y coordinates after the table is drawn. I added a page property called yNewCoord and set this to yNewCoord = y in Completed. Then in my loop, I check the current yCoord. If it’s greater than the PageHeight - a buffer, then I set the new yCoord for either a new page or to continue off of yNewCoord
if yCoord > d.PageHeight - 50 then
if yNewCoord > d.PageHeight - 75 then
g.NextPage
yCoord = 50
else
yCoord = yNewCoord + 30
end if
end if