Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have PrintTest.aspx page load images paths from database and render it in div to print these images maybe up to 20000 image

C#
   for (int i = 0; i < Files.Count; i++)
{
HtmlImage image=new HtmlImage();
    image.ID="ImageAN"+i.ToString();
    image.Src=Files[i].ToString();
    image.Alt="PrintImage";
    image.Attributes.Add("class","PrintImage");

div_Print.Controls.Add(image);
}

then call java-script function to print the content of div_Print

C#
this.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", " PrintContent('div_Print')", true);


java-script function >

JavaScript
 <script type="text/javascript">
function PrintContent(divName) {
    var DocumentContainer = document.getElementById(divName);
    var WindowObject = window.open();
    WindowObject.document.writeln(DocumentContainer.innerHTML);
    WindowObject.document.close();
    WindowObject.focus();
    WindowObject.print();
    WindowObject.close();
}
</script>



but this scenario causes my browser keep crashing and closed i want any scenario to avoid this or print images without render it inside html
Posted
Comments
Dave Kreskowiak 26-Aug-13 10:53am    
How big are these images?? Keep in mind, the browser has to keep every one of those images in memory in order to display it and needs memory to render them AGAIN to print them.

If you're rendering 20,000 images from a DSLR camera, you're going to run the machine out of memory long before you get to 20,000 of them.
jkirkerx 26-Aug-13 16:41pm    
I don't know anything that can do that, maybe grab 16 images at a time, format them in size and placement, print a page, then move to the next 16 images and loop it.

You can use the window.setTimeout method to kick off the next printing after a couple of seconds. This will allow the browser to recover and likely not lock up. However, any time you use a browser to do lots of heavy and intensive processing you lose a certain amount of control because you have not developed the browser. You are at the mercy of the limitations of the browser that is being used, whether IE or FireFox, etc.
 
Share this answer
 
Comments
nagiub2007 27-Aug-13 8:56am    
ok thanks 4 reply i have arraylist of images path in c# how can i print even divide it to stages each stage contain about 100 image how ?
ZurdoDev 27-Aug-13 9:21am    
C# or JS? Your question said you were printing from JS.
nagiub2007 28-Aug-13 16:32pm    
js
ZurdoDev 28-Aug-13 16:33pm    
So, as I said, in JS use the window.setTimeout method to print an image, then wait a half second or whatever and print the next one.
Printing such a big number of images at once is not a good idea. The server will definitely crash; may be you should try giving some time-interval after printing a small number of images just to give your browser a little time to sigh :) This way you will be able to print all of the images (unless browser's memory doesn't reach the limit) but slowly. Otherwise, I don't think there is any way to do this kind of heavy image printing job in the browser.
 
Share this answer
 
Comments
nagiub2007 27-Aug-13 8:55am    
ok thanks 4 reply i have arraylist of images path in c# how can i print even divide it to stages each stage contain about 100 image how ?
In your code, you can use a timer to wait or you can let the current running thread to wait for some milliseconds after 100 or 1000 images and then continue.
 
Share this answer
 
Comments
nagiub2007 28-Aug-13 14:30pm    
ok how to determine the seconds printer will take to print about 100 image
you could try this code but I find three things that are important and need to be considered: #1 it requires a utility to be installed at client machine, #2 it supports Windows clients only & #3 it is not free
 
Share this answer
 

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