如何在asp.net中打印大量图像? [英] how to print a huge number of images in asp.net?

查看:72
本文介绍了如何在asp.net中打印大量图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PrintTest.aspx页面从数据库加载图像路径并在div中渲染它以打印这些图像可能高达20000图像



i have PrintTest.aspx page load images paths from database and render it in div to print these images maybe up to 20000 image

   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);
}



然后调用java-script函数打印div_Print的内容




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

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





java脚本函数>





java-script function >

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







但这种情况会导致我的浏览器保持崩溃和关闭我希望任何方案避免这种情况或打印图像而不在html中显示它




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

推荐答案

你可以使用window.setTimeout方法启动下一个几秒后打印。这将允许浏览器恢复并且可能不会锁定。但是,只要您使用浏览器进行大量繁重的处理,就会失去一定程度的控制权,因为您尚未开发浏览器。您正在使用正在使用的浏览器的限制,无论是IE还是FireFox等。
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.


一次打印如此大量的图像并不是一个好主意。服务器肯定会崩溃;可能你应该尝试在打印少量图像后给出一些时间间隔,只是为了给你的浏览器一点时间叹息:)这样你就可以打印所有的图像(除非浏览器的内存没有到达限制)但慢慢地。否则,我认为没有办法在浏览器中进行这种繁重的图像打印工作。
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.


在您的代码中,您可以使用计时器等待,或者您可以让当前运行的线程在100或1000个图像之后等待几毫秒然后继续。
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.


这篇关于如何在asp.net中打印大量图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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