使用javascript - 横向模式打印到硬拷贝

LIG*_*GHT 4 html javascript css

使用javascript以横向模式打印网页.打印时,我想:

  1. 设置边距
  2. 景观模式

phi*_*hag 10

您可以使用@pageCSS规则标记打印页面的大小和边距:

/* In CSS, not JavaScript */
@page {
  size: A4 landscape;
  margin: 42pt 12pt;
}

@media print {
  /* Define print-specific styles here, for example toning down the decoration
     of hyperlinks and removing the navigation. */
  a {color: inherit !important; text-decoration: none !important;}
  nav {display: none;}
}
Run Code Online (Sandbox Code Playgroud)

然而,浏览器支持是不稳定的 - 除了王子XML,只有IE8 +和Opera支持它.如果您希望对打印进行精确的跨浏览器控制,请考虑(通常是服务器端)PDF输出机制.