如何控制打印字体大小 [英] How to control print font size

查看:171
本文介绍了如何控制打印字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户打印,但是输出太大(我必须在打印对话框中手动调整到大约60%).我使用css媒体查询(如下)来控制内容,并尝试更改html, body{}的字体大小而不更改输出字体大小.打印到Adobe PDF可以正确打印

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?

我的打印链接:

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

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

}

推荐答案

最后弄清楚了这一点,并且有多种原因.最主要的是,我还需要为包含文本的div设置字体大小.在主要的CSS中,我将body字体大小设置为62.5%,将div字体大小设置为130%.当我将@media print {}的正文字体大小设置为12pt时,它继续使用130%div设置,因此打印得非常大.

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.

我相信我通过更改正文字体大小来调整字体大小的工作存在缺陷,因为我将CSS缩小了,并且每次更改后都可能忘记缩小了.

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.

这篇关于如何控制打印字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆