• 0

[HTML or PHP] Inserting Page Break?


Question

How do I insert a page break using either HTML or PHP? I'm creating a utility to automatically create reports, so I have a for() loop printing out all the reports, and at the bottom inside the loop I want to put a page break so each block is on a seperate line.

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

That's a line break. I mean a page break.. i.e. a few lines of code that will automatically print out enough <br>'s that it fills up the rest of the page and leaves me at the start of the next page.

Link to comment
Share on other sites

  • 0

Can you explain to me how this is even possible? You'd have to have different pages, it's not like word where you can just end a page and start the next. Printing out several breaks to push the content to the end of the "page" wouldn't work either, people use different resolutions, etc, and it would never work out. Perhaps I'm missing what you're looking for, but I don't think it's possible (unless of course, you literally use different pages).

Link to comment
Share on other sites

  • 0

you could use some javascript trickery to detect the users resolution and create a table with rows of that particular height. then you just loop through printing out your data to different rows if a new page is required. this would work for on screen "pages" but if you want to print this to a printer then i have no idea.

Link to comment
Share on other sites

  • 0
Can you explain to me how this is even possible? You'd have to have different pages, it's not like word where you can just end a page and start the next. Printing out several breaks to push the content to the end of the "page" wouldn't work either, people use different resolutions, etc, and it would never work out. Perhaps I'm missing what you're looking for, but I don't think it's possible (unless of course, you literally use different pages).

Er, yeah, I mean literally different pages. Sorry for not making that clear.

Its a report that will be printed out. I want each block to be at the top of each page. I believe all printers would print it almost the same.. I dont care how it looks on the monitor, I just want it to print on seperate pages.

Link to comment
Share on other sites

  • 0

I think you're looking for something like this page:

http://www.w3.org/TR/REC-CSS2/page.html

ex.

&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
@page { size 8.5in 11in; margin: 2cm }
div.page { page-break-after: always }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="page"&gt;Page 1 Here&lt;/div&gt;
&lt;div class="page"&gt;Page 2 Here&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

try that in a browser, shows up right after each other, press print preview and they are on 2 separate pages.

Link to comment
Share on other sites

  • 0

Pretty interesting problem.

The standard Form Feed character for a printer is ASCII 12 (dec). Not sure if you can get a PHP page to start dumping raw codes like that to the printer (and, for modern printers that print graphical images, it won't work unless you are just dumping raw ASCII text to begin with (or use mostly text, and have only a few controlled images - force the form feed in the middle of the text any time, just not in the images).

[EDIT: The post above mine looks like your best solution!] :yes:

Link to comment
Share on other sites

  • 0
i'm pretty sure thats impossible unless you make the php script make a word document and then download and print using word

Hmm, thats not a bad idea actually. Is that possible? If so, how? If I can do that, then I can get rid of the ugly URL, page numbers, time, and header that show up on the HTML-printed pages.

@wesdeboer: Thanks a lot, welcome to neowin! I'll definitely try that one out.

If someone could give more insight on the Word thing as well, it would be much appreciated.

Link to comment
Share on other sites

  • 0

here is something to try in the lines of the word doc creation.

http://www.fpdf.org/

I haven't tried it yet, but was looking to check it out for a similar reason that you have. It should be able to generate paged pdf files for printing.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.