page breaks for printing

disaster-master's picture

She has: 2,154 posts

Joined: May 2001

Got a little bitty tiny question.

I am trying to fix a web page so that when it is printed it will break when told too. Like fix it so that it will carry a paragraph over to the next page when it is printed instead of cutting it in half. Can I do this?

*i know it can be done....just know it*

Busy's picture

He has: 6,151 posts

Joined: May 2001

a little bitty answer (probably not but sounds good Laughing out loud)

I dont think there is any code or tag as such, and a lot would depend on the users printers options (header and footer settings) but I guess you could set your print page up so the paragraph ends before the page ends, this is why i use edit pad as editor, i can use the print option set to printer specs and adjust before printing as it offers options before printing. but other way is set your page out try print it (or print it from IE or whatever), adjust your line breaks to make your layout print as needed on your machine (use default margin settings) and hopefully should be pretty universal and not cut content in half.

disaster-master's picture

She has: 2,154 posts

Joined: May 2001

But...but....but...there is. You can do it is CSS 2. There are the marks, orphans, page break thingys. I just don't know how to code this into the page.

I realize that it won't work for older browsers but if I fix it now then when they die it will work in all of them.
Besides they should UPGRADE if they want to enjoy my page breaks. Laughing out loud hehe....just kidding.

*gosh, i've been coding to long today/tonight/this morning*

SUZANNE!!!!!!! Where are you?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

It's 2 am my time, I'm sleeping!

What you need to do is set a print stylesheet. In that stylesheet, you can specify a lot of information, but Busy is right, the printer specs will affect where the cut off is and can throw your nice work into disarray.

What it's usually used for is when the web media is supposed to be printed (or can be viewed as print-preview). @PAGE

Now I really recommend you get a book like Core CSS to help you along on this one. There are a few properties for page break:

page-break-before
page-break-after
page-break-inside

There is also, page, widows, orphans, size and marks.

http://www.htmlgoodies.com/beyond/css_print.html has a basic tutorial.

Happy experimenting! Don't forget to check online resources like http://jigsaw.w3.org/css-validator/ for any glaring problems in your code.

Smiling Suzanne

Edit: in the @print stylesheet, you would specify that you print before a paragraph. You would have to specify a class to get it to print before a specific paragraph (or ID) and set that in the stylesheet.

disaster-master's picture

She has: 2,154 posts

Joined: May 2001

If any dear soul just happens to be working on this I have figured out how to print another page after every paragraph by including this in the head:

But I don't need a break after EVERY paragraph. What I need now is to be able to specify one page break only at one certain place on a page. Like at the end of a table or image or paragraph. Not just the paragraphs. It will depend of the content of the page where the break will need to be.

*ADD ON*

Suzanne,
I guess you and i posted about the same time. Thanks. I am going to get me a book tomorrow on CSS and javascript. (and a new mouse)Wink I am sorry to be such a pain but when I get my mind on something it is hard to let it go. For some reason I am in high gear tonight. if you all get tired of me posting stupid questions just tell me so and I will slow down. I am just learning so much lately. Thanks to you all.

Nite nite.
DM

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

Good luck on using those. I have used the page-break-after before for a HTML version of my resume. They worked pretty good most of the time. The main problem is that they are quite hard to actually test. Not only do you need several different OS's, you need different printers also. On my printer, it prints perfectly. On other printers, it doesn't always.

What I had the most luck with was this:

<?php
<DIV STYLE=\"page-break-after: always\">
?>

when I wanted a page break.

Also I did find the best js print function:
In the head of html

<?php
&lt;script&gt;

function
printpage() {
    if (
window.print) {
       
window.print();
    } else {
       
alert('To print this page, select Print from the file menu.');
    }
}
// -->
&lt;/script&gt;
?>

In the body for a print link:
<?php
<a href=\"#\" onClick=\"printpage(); return false\" title=\"Click to Print\">Print!<
?>

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

disaster-master's picture

She has: 2,154 posts

Joined: May 2001

The tutorial at htmlgoodies what just what I was looking for combined with mairvings print option script. Worked perfectly on my printer. I'll keep my fingers crossed for other printer testing. Also validated my css at W3C.Laughing out loud and html Laughing out loud Don't ya just love it when things validate? I get a smug satisfaction out of doing that. LOL

Thanks you three!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.