C#.net 4.0中的PrintDocument [英] PrintDocument in C#.net 4.0

查看:82
本文介绍了C#.net 4.0中的PrintDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PrintDocument中显示页面(可能至少有1000页).
在PrintPreview Control中,显示文档需要很长时间.
有没有一种减少时间的方法?

I want to display the pages in a PrintDocument(may atleast 1000 pages).
In PrintPreview Control it takes a long time to display the Document.
Is there a way to Reduce the time ?

推荐答案

我不知道您的确切要求,但是如果您想为Page进行打印预览,那么最简单的解决方案是编写如下的Java脚本

我不记得从哪里找到下面的Javascript了很长时间,但是它一直对我有帮助

I dont know your exact requirement ,but if you want a print preview for your Page then the most simplest solution is to write a Javascript as below

i dont remember from where i found the below Javascript it was quite a long time , but it has always worked wondoers for me

<script language="javascript" type="text/javascript">

        function PrintContent() {
            printWindow = window.open("", "mywindow", "height=650,width=999,scrollTo,resizable=1,scrollbars=1,location=1");
            var strContent = "<html><head>"; // If you use this script inside <head> on the page, there might be error. So I am keeping inside body (becaue of <head>)
            strContent = strContent + "<title>Print Preview</title>";
            strContent = strContent + "<link href='../../App_Themes/Default/Page.css' type='text/css' rel='Stylesheet' />";
            strContent = strContent + "</head>";
            strContent = strContent + "<body>";
            strContent = strContent + "<div style='width:100%;text-align:left;'>";
            strContent = strContent + "<img alt='Imageid' src='../../Images/Logo.jpg' />";
            strContent = strContent + "</div>";
            strContent = strContent + "<div style='width:95%;text-align:right;'>";
            strContent = strContent + "<img alt='PrintID' title='Print' class='PrintIcon'  src='../../Images/printicon.jpg' onclick='window.print()' />";
            strContent = strContent + "</div>";
            strContent = strContent + "<div style='width:100%;'>";
            strContent = strContent + document.getElementById('PrintArea').innerHTML;
            strContent = strContent + "</div>";
            strContent = strContent + "</body>";
            printWindow.document.write(strContent);
            printWindow.document.close();
            printWindow.focus();
            return false;
        }
    </script>




使用完javascript之后,您将在Javscript中看到以下内容,如下所示:




Once you done with javascript ,you will see the line inside a Javscript as below

strContent = strContent + document.getElementById(&#39;PrintArea&#39;).innerHTML;


PrintArea是您需要打印的区域,因此所有需要打印的页面内容都应位于打印区域"下

如果您有多个区域,则可以按照以下内容编写


the PrintArea is the one which you need to print , so all the content of page which need to be printed should come under Print Area

if you have multiple area you can write as per below

strContent = strContent + document.getElementById('printHeader').innerHTML;
strContent = strContent + document.getElementById('printTitle').innerHTML;
strContent = strContent + document.getElementById('divApplcicationStatus').innerHTML;
strContent = strContent + document.getElementById('Print5').innerHTML;
strContent = strContent + document.getElementById('Print1').innerHTML;
strContent = strContent + document.getElementById('Print2').innerHTML;




然后在您要单击的按钮上单击以加载打印预览,请按照




amd then in your button on which click you want to load a print preview you do following

<asp:Button ID="btnPrint" runat="server" CssClass="button" Text="Print" OnClientClick="return PrintContent();" /></td>
          <td style="width: 10%">


这篇关于C#.net 4.0中的PrintDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆