Javascript 以横向格式打印

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13684128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 12:39:36  来源:igfitidea点击:

Print in Landscape format

javascriptprinting

提问by user1820973

Possible Duplicate:
Landscape printing from HTML

可能的重复:
从 HTML 横向打印

I am using below code to show print window on button click:

我正在使用以下代码在按钮单击时显示打印窗口:

function print_onclick() {
    window.print();
    return false;
}

I want the page to be printed in Landscape format. Is there any property I can add in above code to make it work ?

我希望页面以横向格式打印。我可以在上面的代码中添加任何属性以使其工作吗?

Additional Info: Since my page width is 1280 px, when I print it on A4 paper with portrait orientation, the font becomes too small. I want to print only 2 lines. If not landscape, is there a way I can fix the font size of those table cell/divs while printing ?

附加信息:由于我的页面宽度是 1280 像素,当我在 A4 纸上纵向打印时,字体变得太小。我只想打印 2 行。如果不是横向,有没有办法在打印时修复这些表格单元格/div 的字体大小?

回答by hereandnow78

you cannot set this in javascript, you have to do this with html/css:

你不能在 javascript 中设置它,你必须用 html/css 来做到这一点:

<style type="text/css" media="print">
  @page { size: landscape; }
</style>

EDIT: See this Question and the accepted answer for more information on browser support: Is @Page { size:landscape} obsolete?

编辑:有关浏览器支持的更多信息,请参阅此问题和已接受的答案:@Page { size:landscape} 是否已过时?