【问题标题】:print the content of a div打印一个div的内容
【发布时间】:2012-07-05 07:29:14
【问题描述】:

我需要打印一个 div 的全部内容。注意 div 中的滚动。 但是当我使用Window.print() 打印它的内容时,它只打印屏幕上的可见部分。我想打印网格中的所有 154 条记录,但它只打印了 21 条记录。

注意:我不想打开新窗口。

编辑:

javascript function()
{
1. Hide divs that you don't want to print
2. window.print()
3. show the divs you hide in step 1
}

【问题讨论】:

标签: javascript jquery printing


【解决方案1】:

我认为最强的解决方案是创建一个 iframe,将要打印的内容复制到该框架,然后打印它。有用于此的 JQuery 插件。重复:Print the contents of a DIV

另一种可能性是使用打印 CSS 来隐藏您不想打印的内容(菜单等),并移除表格上的最小高度,从而移除滚动条。

【讨论】:

    【解决方案2】:

    使用带有打印媒体类型的样式表 -

    link rel="stylesheet" type="text/css" media="print" href="print.css"
    

    并更改 DIV 样式 -

    height:auto;
    overflow:auto
    

    打印时(使用window.print()),DIV 将增加高度,并隐藏所有其他 DIV。

    【讨论】:

      【解决方案3】:

      试试这个,但首先包含这个library

      $('YourDiv').printElement();
      

      或者

      Div Printing阅读这篇文章

      【讨论】:

      • printElement()..我需要为此使用一些库吗?
      【解决方案4】:

      https://github.com/jasonday/jquery.printThis

      我基于其他几个插件编写了上述插件,它允许在页面上打印元素(无弹出窗口)并维护页面样式或专门为打印元素加载新的 css 样式。

      【解决方案5】:

      我使用了 printThis,它适用于具有固定高度和滚动条的 div。 removeInline: true 属性会打印整个文档,即使您在 div 中只能看到它的一部分。

      function printpage(divId, title) {
                          var divID = "#" + divId;
                          var divTitle = title;
                          $(divID).printThis({
                              debug: false,
                              importCSS: true,
                              importStyle: true,
                              printContainer: true,
                              pageTitle: divTitle,
                              removeInline: true,
                              printDelay: 333,
                              header: null,
                              formValues: true
                          });
      
                      }
      

      【讨论】:

        猜你喜欢
        • 2011-01-16
        • 2021-09-13
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        相关资源
        最近更新 更多