0

I should write a long html table and it will stay on several pages. They asked me to "manually" handle the number of rows to be printed on each page, and this number depends on the available space on the pages (and for each page the available space will be different, for sure).

They don't want to have un-managed, and potentially logically wrong, breaks in the table.

Now:

I have a loop printing row by row:

while ($rowitem = mysqli_fetch_array($connitem))
{           
    $name = $rowitem['name'];
    echo("<TR><TD>$name</TD></TR>");    
}

I can check if the available remaining length of the page is enough for the next row.

How can I determine the length of the available free space (let's say until the <footer> tag) on my current page?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Ale MaDaMa
  • 25
  • 4
  • Are you printing this directly from PHP to a printer? Or is PHP just outputting content to a browser and letting the user print the page from there? It's not clear. – ADyson Dec 01 '21 at 09:50
  • to the browser, not directly to the printer – Ale MaDaMa Dec 01 '21 at 09:52
  • 2
    Then what's your actual definition of a "page"? – CBroe Dec 01 '21 at 09:54
  • Please clearify: are you creating a PDF or a webpage? – Definitely not Rafal Dec 01 '21 at 09:54
  • `to the browser`. In that case, you have no control over the paper size, margins, zoom and other print settings the user is using. Also, some JS might conceivably make changes to the page during use. So there's really not much PHP can do to influence it, IMHO. The browser's print function just makes the best job of fitting the HTML onto the page that it can. Web pages were never really intended for printing. There's such a thing as "print" CSS though, btw. But if you really want fine control over the process, have your application generate a PDF instead (which the user can then print). – ADyson Dec 01 '21 at 09:54
  • hi all and thank you for your interesting suggestions and evaluations. Guess I will go through the PDF. I could stream the PDF to the screen. But in this case, how can I control my loop? how can I determine if a row can be printed? – Ale MaDaMa Dec 01 '21 at 13:54
  • please consider that one column is a "textarea", then I don't know a priori the row height – Ale MaDaMa Dec 01 '21 at 14:04
  • @bubibuma You have to do some research yourself. Here's a good start: [Print table in pdf using php](https://stackoverflow.com/questions/31239721/print-table-in-pdf-using-php) – Definitely not Rafal Dec 01 '21 at 15:54
  • @DefinitelynotRafal I already did it, long research but if I ask here is because I didn't find anything elsewhere... – Ale MaDaMa Dec 01 '21 at 16:11

0 Answers0