【问题标题】:How to customize the printing while using Window.print?使用 Window.print 时如何自定义打印?
【发布时间】:2010-06-02 05:15:04
【问题描述】:

我想打印一张发票,我通过 media=print 使用 print.css,当我将当前样式表更改为 print.css 时,我可以查看我应该打印的内容,而标题和内容没有左对齐。

但在我打印时,顶部和左侧仍有空间,它占据了整个 a4 纸和页面的整个宽度。但我定义的正文宽度仅为 550 像素。

当我查看打印预览时,它占用整个宽度而不是占用宽度的 1/3..

我的 print.css 是

body {
  width:550px;
  height:450px;
  color:#000000;
  margin:0;
  padding:0;
  word-spacing:1.1pt;
  font-family : "Times New Roman", Times, serif;
  font-size : 10px;
  text-align:left; 
}

a {
  visibility :hidden;
  display : none;  
}

input{
  display : none;  
}

table { margin: 1px; text-align:left; }

#list,#head,#cont,#fotter,#oth,#links,#name,li,ul,ol {
  display : none;  
}

我正在使用window.print通过浏览器进行打印,所以我需要做任何特殊配置吗...?

【问题讨论】:

    标签: javascript css printing


    【解决方案1】:

    不幸的是,您在使用 window.print(或任何其他 JavaScript 方法)时无能为力。

    让您的页面以您想要的方式打印的唯一方法是选择文件 > 打印预览,然后在那里配置任何布局设置。例如,在 Firefox 上,您可以使网页横跨一张 A4 纸。

    【讨论】:

    • 我的要求是我想打印一张小额零售账单,我只需要 550px 宽度,高度只取决于账单的长度。如果只有两个项目,那么我需要它只取纸的一小部分而不是整张纸。实际上我可以从浏览器中打印出什么。有没有其他简单的方法而不使用 window.print?跨度>
    • 好吧,你可以看看从 Java Applets 打印(见这篇文章:stackoverflow.com/questions/438397/…)。或者,使用 PHP,您可以输出一个包含一些 JavaScript 的 PDF 文件来自动打印。 (我不知道如何实现它 - 试试 Google 搜索?)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多