2012-07-05 127 views
1

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

enter image description here

注:我不想打开一个新窗口。

编辑:

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

对不起,如果你不帮我一些代码,我帮不了你。 –

+0

@vaibhav,使用这个jquery插件'http:// projects.erikzaadi.com/jQueryPlugins/jQuery.printElement /' –

+0

你有没有看到这个:http://stackoverflow.com/questions/2255291/print-the-contents- of-a-div –

回答

0

试试这个,但首先包括此library

$('YourDiv').printElement(); 

或者

阅读这篇文章上Div Printing

+0

printElement()..我需要为此使用一些库吗? –

+1

这是一个jQuery插件。 –

+0

@vaibhav。是的,我更新了答案 – Talha

1

在S我认为最好的解决方案是创建一个iframe,将要打印的内容复制到该框架,然后将其打印出来。有这个JQuery插件。重复:Print the contents of a DIV

另一种可能性是有一个打印的CSS隐藏你不想打印的东西(菜单等),也删除了你的表的最小高度,导致滚动条被删除。

1

使用样式表打印的介质类型 -

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

并改变DIV的风格 -

height:auto; 
overflow:auto 

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

0

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

我写了一个基于几个人上面的插件,它允许一个页面上的元素的印刷(不弹出),并保持页面样式或专门为打印元素加载新的CSS样式。

+0

https://stackoverflow.com/questions/29482477/how-do-i-print-the-entire-bootstrap-modal-where-content-in-modal-body-is-scrolle/29523921 #29523921 – shazia

0

我使用了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 
        }); 

       }