Need help with page formatting for printer.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jack.Straw
Forum Newbie
Posts: 11
Joined: Thu Nov 30, 2006 11:12 am

Need help with page formatting for printer.

Post by Jack.Straw »

Hi. I've put together an application for work that reads excel files and then displays them as html forms. Users can then edit the form and click a 'print' button which loads a printable table displaying formatted results. This all works quite well, except.. page breaks.

The table on the 'print' page will have an unpredictable number of rows, and each row has an unpredictable number of carriage returns. How could i get my program to close the table at the end of page 1 and start again on page 2? The table is created within a loop. Is there any way to tell where the end of a printable page is so that i can make this thing work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Generate a PDF, it's the only way to reliably control it.
Jack.Straw
Forum Newbie
Posts: 11
Joined: Thu Nov 30, 2006 11:12 am

Post by Jack.Straw »

uggg.. ok, i'll look into that. Thanks!

-Jack
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

I noticed you didn't suggest using CSS "paged media" output.
Is there ever going to be a browser that supports it, do you think?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Bill H wrote:I noticed you didn't suggest using CSS "paged media" output.
Is there ever going to be a browser that supports it, do you think?
Probably at some point, but until the majority support it, I can't very easily do so.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Oh, I was not trying to imply that you should have suggested it.
Au contraire, I was glad you didn't.

Some time ago someone led me into that pitfall and I fiddled with it for several days until it was finally pointed out to me that not one single browser in the universe (at that time) supported it. I was a bit annoyed. I went the PDF route, as I recall.

But it will be a nice feature when it does get support, as it is clean and straightforward.

Does any browser support it at this point?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Check for support in Opera - they're usually pretty anal about supporting every standard.
Jack.Straw
Forum Newbie
Posts: 11
Joined: Thu Nov 30, 2006 11:12 am

Post by Jack.Straw »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok, i've done some research on creating pdf files with PHP.  That's great!

However...

I face the same problem with the pdf file as I do with regular html.  How do i know when my table has reached the end of the page?  To be clear on what my program is doing, please see this example:

Code: Select all

<table>
  <tr>
    <?PHP
    for ($i=0; $i<count($rows); $i++) {
      if (END OF PAGE) {
        echo "</tr></table>";
        StartNewPage();
        echo "<table><tr>";
      }
      echo "<td>$rows[$i]</td>";
    }
    ?>
  </tr>
</table>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

remember: you're making a PDF, not HTML - you should be placing individual elements at x & y co-ordinates relative to a corner of the page.

So a table would become nothing but a series of "cells" of content.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is there a way to use the page-break-inside: avoid; CSS directive?
Jack.Straw
Forum Newbie
Posts: 11
Joined: Thu Nov 30, 2006 11:12 am

Post by Jack.Straw »

Kieran Huggins wrote:remember: you're making a PDF, not HTML - you should be placing individual elements at x & y co-ordinates relative to a corner of the page.

So a table would become nothing but a series of "cells" of content.
I understand, but the root of the problem to begin with is that i never know exactly how much information going to be in any given field (it's mostly user input). Placing the first row would be no problem, but where do i start the 2nd? How do i know when it's time to start a new page? I guess i could count the characters in each string.. hmm
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ezpdf makes report generation pretty simple.
Jack.Straw
Forum Newbie
Posts: 11
Joined: Thu Nov 30, 2006 11:12 am

Post by Jack.Straw »

ezpdf worked great! thanks so much!!
Post Reply