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

javascript - Force webpage to print in legal paper - Stack Overflow

programmeradmin1浏览0评论

In a web application for an intranet, I have a webpage that has to be printed by the user in legal (8 1/2" x 14") paper.

Is there a way using CSS or JavaScript to tell the browser to request (or optimize) for this paper size? If there isn't, is it possible to at least change the default printer settings for this particular webpage so the user doesn't have to specify Legal Paper manually?

Thanks in advance for your kind answers.

In a web application for an intranet, I have a webpage that has to be printed by the user in legal (8 1/2" x 14") paper.

Is there a way using CSS or JavaScript to tell the browser to request (or optimize) for this paper size? If there isn't, is it possible to at least change the default printer settings for this particular webpage so the user doesn't have to specify Legal Paper manually?

Thanks in advance for your kind answers.

Share Improve this question asked Feb 18, 2013 at 20:16 MeryoviMeryovi 6,2315 gold badges43 silver badges67 bronze badges 3
  • Whenever I see the word "force" in a requirement the first thing I think is: You're doing it wrong. – Joel Etherton Commented Feb 18, 2013 at 20:20
  • In this case I can assure you I'm not doing it wrong and it is an actual requirement. – Meryovi Commented Feb 19, 2013 at 3:07
  • You missed my meaning. The message was aimed at the requirement. In most cases, when the requirement is designed to "force the user", it's a pointer that there is probably something wrong with the requirement, not the code. – Joel Etherton Commented Feb 19, 2013 at 3:43
Add a ment  | 

3 Answers 3

Reset to default 3

This can't be done with standard CSS or JavaScript. You might be able to do this with ActiveX but I can't say that for sure and even then it will only work in IE.

If this can't be achieved via CSS/JS, an alternative would be to dynamically generate a PDF that is legal size from the HTML. There are plenty of HTML to PDF converters, one of the best open source options is mPDF

You can try CSS and see if that will work for you. It seems to work with a few of my printers, but not all.

@media print {
    body {
    width:816px;
    height:1344px;
    }
发布评论

评论列表(0)

  1. 暂无评论