Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra blank page when I print (except in IE) - is it my print css?

I am using print css to hide certain elements and also to stop page breaks when I don't want them. The user can choose to hide sections before they print.

My problem is that when I print-preview there is always an extra blank page (at the end in Chrome and Firefox, and at the beginning in Opera) and I cannot figure out why. IE does not have a problem, no extra pages (which is shocking...)

I would greatly appreciate some input. I have tried making the container div page-break-after: avoid; and page-break-after: auto; but neither worked. Also taking out the table.plain { page-break-inside:avoid; } did not make a difference.

The exclude class is added to a table when the user clicks the hide icon. This works and anything with the exclude class does not show in print. The final page the user wants to print may fit on one page or may not.

Here is my html:

<body>
    <div id="main">
        <div id="content">
            <div id="side" class="exclude">
                ...logo, etc, shown at side on screen...
            </div>            
            <div id="data">
                <table class="printOnly plain printHeader">
                    ...logo, etc, to print at top...
                </table>                
                <div>
                    <table class="detail plain">
                        <tbody>
                            <tr>
                                <td class="rel">
                                    <div class="abs exclude visibility">
                                        <a href="#" class="show ico-show ico hid">Show</a>
                                        <a href="#" class="hide ico-hide ico">Hide</a>
                                    </div>
                                    <h3>Contact</h3>
                                </td>
                            </tr>
                            ...more tr with contact details...
                        </tbody>
                    </table>
                    ...more tables with other details...
                </div>
            </div> //data
        </div> //content
    </div> //main
</body>

Here is my print css:

@media print {
    .exclude {
        display: none !important;
    }

    .printOnly {
        display:block !important;
    }

    div#data,
    div#data div {
        width: 98% !important;
        border: none !important;
    }

    table.plain { page-break-inside:avoid; }
}

Many thanks in advance for your help :)

like image 937
tekiegirl Avatar asked Jun 17 '13 10:06

tekiegirl


People also ask

Why does my printer print out an extra blank page?

Corrupted or incomplete software could cause the printer to feed a blank page after each print job. Disconnect the USB cable from the printer, if necessary. In Windows, search for and open the Control Panel.

How do I stop my printer from printing extra blank pages?

Locate your printer, right-click it, and choose Printing Preferences. Go to the Paper tab and there you should see the Separators option. Set it to No Separators and save changes.

What is @media print?

Print media, as you know is one of them. Print media is one of the oldest and basic forms of mass communication. It includes newspapers, weeklies, magazines, monthlies and other forms of printed journals. A basic understanding of the print media is essential in the study of mass communication.

How do you write a print page in CSS?

You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters.


1 Answers

Most of the times you’ll specify

html, body { width: 100%; height: 100%; }

The print driver in your browser doesn’t like this. So to fix that just add this to your print.css file

html, body { height: auto; }

No more blank page printing.

the solution is explained at this page hope helps everyone

like image 185
mahdi gh Avatar answered Sep 27 '22 18:09

mahdi gh