Click here to Skip to main content
15,914,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ?
Posted
Comments
Rickin Kane 10-Sep-12 6:02am    
you need to print a single page or multiple page at once , means do u wish to print the curent open page
Joseph Vincent 17-Sep-12 9:00am    
Single page at a time will be handy...

1 solution

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

XML
<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>



Once you done with javascript ,you will see the line inside a Javscript as below
C#
strContent = strContent + document.getElementById(&#39;PrintArea&#39;).innerHTML;

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

C#
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

XML
<asp:Button ID="btnPrint" runat="server" CssClass="button" Text="Print" OnClientClick="return PrintContent();" /></td>
          <td style="width: 10%">
 
Share this answer
 
v2
Comments
abhipriy 22-Feb-13 6:56am    
How to print PRN file in C#.net ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900