We help IT Professionals succeed at work.

CSS/JavaScript Printing Problems.. is it possible....

572 Views
Last Modified: 2013-11-19
Hello,

I am aware of the many discrepancies between IE, Printers, CSS, and JavaScript that disallow any type of "controlled" printing. But I haven't seen any questions for this problem that I have. Maybe you can help.

I am designing a printer friendly page for a report that is generated dynamically. There's no telling how much or how little information will be on each page. I'm using the "Page-Break-Before: always" CSS property which is working great. But when there is not enough information to fill up the entire page, the contents are aligned in the middle of the page. But, For some reason this only happens to a couple pages. Some are aligned at the top even though that page doesn't have enough content. So that leads me to believe it's not really an issue with the amount of content on the page.

I'm wondering if there is some alignment property for the printer that forces it to start printing at the top of each page no matter what. Sometimes when the information is too big for one page it spits the LAST TWO LINES directly in the middle of the page. This is no good.

Any suggestions?

Thanks in Advance!!!



Comment
Watch Question

Top Expert 2004

Commented:
No good suggestions. These problems are going to crop up again and again until we have more control over the printing process.
About the only way I know of to really control the output is by generating a PDF from the content (or at the very least, an Office file.) It's still not perfect, but it's much closer.
Top Expert 2004

Commented:
>>Sometimes when the information is too big for one page it spits the LAST TWO LINES directly in the middle of the page. This is no good.

Just to add - I agree completely, but it's the nature of the beast. You'll drive yourself nuts trying to format it. There are some Activex solutions for an IE only environment, and Crystal Reports has some control over the printing process, but it's still going to be an awkward solution - escpecially with CSS. It simply doesn't give us the "exact" control that you're looking for.
Top Expert 2004

Commented:
just out of curiosity, what are you using the Page-Break-Before attribute on?
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2013

Commented:
I printed it on an HP LJ8000 and it look fine to me.  It would be preferable to get a little different page braking but , it you play with it to get it to work for on printer, it will not be correct for another when I print it .  On my Lexmark CJ720 there is a difference in th epage breaks and on my Tandem 5577 I get three different results depending on which driver I use, so in short; I would leave it alone if it is being printed by the end user, becaue you don't have control of what they use t pront it.  All the results I got give decent printed presentation, and the formatting quirks are not a big deal.

If you are printing it in house and will always use the same printer, you could play around with the page-breaks to get it the way you want it for that specific printer.  Or all the way back to what George originally indicated, you go with a PDF if it is critical.  Given the 18 page length of the report, I think it is not realistic to think yu are going to get it to print perfectly using an HTML page.

Cd&
Top Expert 2004
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2004

Commented:
...I'm not sure how much value this is going to have in the PAQ, as it's "so" specific to your situation, and may not be of much use to anyone else...but hopefully we have helped set your mind at ease a bit about your options.
Have you tried using the "@media print" style command?

Example:
<style type="text/css">
@media print {
.your_class {top: 5px; left: 5px;}
}

@media screen{
.class1
.class2
.class3
.
.
.
}
</style>

I use this command to format my entire site for printing, and it works perfect.  All you need to do is define each class that isn't printing correctly, then change some of its attributes in the @media print class.  As for the rest of your css, that should go in the @media screen class.
Top Expert 2013

Commented:
Split  seanpowell and COBOLdinosaur  IMHO

Cd&
Top Expert 2004

Commented:
Always fun when you spend 3 hours on something and never hear back.

Author

Commented:
Sorry about that guys. I didn't realize people were still responding to this.

Seanpowell, after your first response of not knowing what to do I thought I was out of luck. But if you did research to find out more info (I havent read the rest of these replies yet) then you did yourself some good by finding out.

Anyway, I really appreciate all the help I get here and I do not want to cheat people out of points nor be greedy about them. If it's possible I would be glad to give you guys extra points for your trouble.

I am going to read that Help document how to close these out to avoid this in the future.

Author

Commented:
Just read all the new replies. I tried to tell this guy that it's pretty much impossible but he won't accept that.

Seanpowell, you're saying that maybe I just need to use the page breaks outside of the nested tables to get it to work? I had it under just one table at first and it still didnt work, but it pretty much has to be in nested tables with the report im generating.

At best, at least I have definitive "It's not practical in HTML".

Thanks again for all insight.
Top Expert 2004

Commented:
Better late than never :-)

>>maybe I just need to use the page breaks outside of the nested tables to get it to work?

Without a doubt. There is no way to generate page breaks within nested tables - each section simply must be in it's own table to get close to what you need.

>>but he won't accept that.
He will have to I'm afraid. HTML was just not designed to be printed, even in the best of times. There are workarounds, and activex programs that can give you a "degree" of control, but the only valid option is to create the documents in page layout software (Word, Quark, Pagemaker, etc.)

Thanks :-)
Sean

Author

Commented:
Thanks Sean. I might try to re-code it but like you said it will be a lot of work.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.