简体   繁体   English

当用户在运行时选择页面大小时,window.print()设置窗口高度宽度(mm)

[英]window.print() set window height width in mm when user select page size at run time

I am developing a portal in which user select page size (in mm)and when print preview open then it will be in page size which user have selected. 我正在开发一个门户,用户可以在其中选择页面大小(以毫米为单位),当打印预览打开时,它将是用户选择的页面大小。

is this possible to set page size in mm choosen by user at run time through window.open(). 是否可以通过window.open()在运行时由用户选择以mm为单位设置页面大小。

在此输入图像描述

You can set size in @page media before calling window.print 您可以在调用window.print之前在@page媒体中设置大小

var css = '@page { size: 50mm 50mm; }',
    head = document.head || document.getElementsByTagName('head')[0],
    style = document.createElement('style');

style.type = 'text/css';
style.media = 'print';

if (style.styleSheet){
  style.styleSheet.cssText = css;
} else {
  style.appendChild(document.createTextNode(css));
}

head.appendChild(style);

window.print();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM