最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to control print font size - Stack Overflow

programmeradmin3浏览0评论

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 */
    }

}

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 */
    }

}
Share Improve this question asked Sep 7, 2015 at 1:00 mseifertmseifert 5,6709 gold badges44 silver badges104 bronze badges 8
  • These code works... I think the problem is the cache.. Try to open in private mode browser.. – brunocascio Commented Sep 7, 2015 at 1:06
  • Because the CSS only works for print? Not when viewed on screen? – Joseph Commented Sep 7, 2015 at 1:07
  • I am using Firefox, but tried printing in Chrome with the same result. – mseifert Commented Sep 7, 2015 at 1:07
  • 1 If you have external CSS, which you should, it will be saved in your cache. Clear your cache. Firefox can be set up to do this when you close your Browser. – StackSlave Commented Sep 7, 2015 at 1:08
  • 1 Yes, but I wonder where it pulled the jumbo font size from.I haven't been playing with css font size at all, otherwise I would have thought cache right away. Thanks for your help. – mseifert Commented Sep 7, 2015 at 1:45
 |  Show 3 more comments

1 Answer 1

Reset to default 15

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.

发布评论

评论列表(0)

  1. 暂无评论