Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control print font size

I am allowing my users to print but the output is way too large (I have to manually adjust to about 60% in the print dialog). I use a css media query (below) to control the content and have tried changing the font-size of the html, body{}without any change to the output font size. Printing to Adobe PDF prints correctly

Any ideas what I am doing wrong?

My Print Link:

<a href="#" onclick="window.print(); return false;"></a>

My css:

@media print {
    body * {
        visibility: hidden;
    }
    .printme, .printme * {
        visibility: visible;
    }
    .printme {
        position: absolute;
        left: 0;
        top: 0;
    }
    .printme, .printme:last-child {
        page-break-after: avoid;
    }

    .display-none-on, .display-none-on * {
        display: none !important;
    }
    html, body {
        height: auto;
        font-size: 12pt; /* changing to 10pt has no impact */
    }

}
like image 610
mseifert Avatar asked Sep 07 '15 01:09

mseifert


1 Answers

Finally figured this out and there were multiple causes. The main thing is that I needed to also set the font-size for the div that contained the text. In the main css, I have body font-size set to 62.5% and the div font-size set to 130%. When I set the body font-size for @media print{} to 12pt, it continued to use the 130% div setting and so printed very large.

I believe my efforts to adjust the font-size via changing the body font-size were flawed because I minify my css and probably forgot to minify after each change.

like image 124
mseifert Avatar answered Oct 23 '22 23:10

mseifert