1.在页面头部加入以下代码,以确保打印输出为彩色图像,并设置分辨率为300 DPI。
protected void Page_Init(object sender, EventArgs e) { if (!this.Page.ClientScript.IsStartupScriptRegistered("Print")) { // Set printing options this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Print", "var printing = false; function printEOI() {if (!printing){ printing = true; window.print(); }};", true); } }
2.在需要打印图像的页面上,将图像的CSS样式更改为以下代码:
img.print { filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0) progid:DXImageTransform.Microsoft.Chroma(color='#999999') /* Change #999999 to the color you want the image to be */ progid:DXImageTransform.Microsoft.Alpha(opacity=100) }
3.在打印时,通过以下代码将图像的CSS类应用于要打印的图像。这将确保图像在打印输出中保持与屏幕上相同的颜色。
// Apply print CSS to image Image1.CssClass = "print"; // Call the print function ClientScript.RegisterStartupScript(Page.GetType(), "Print", "printEOI();", true);