System.Drawing.PrinterExceptio ...

编程入门 行业动态 更新时间:2024-10-14 00:29:13
本文介绍了System.Drawing.PrinterExceptio ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

伙计们 在网上找到此代码即可在文件夹中打印文件.现在我得到一个错误

Hi Guys Got this code in the net to print a file in a folder. Now I get an error

"System.Drawing.PrinterException:No printers are installed"

我的网络中有打印机. 下面是代码

I have the printer in the network. Below is the code

public void printimage() { string path = Server.MapPath("~/bin/Reciept3.rtf"); reader = new StreamReader(path); //Create a Verdana font with size 10 verdana10Font = new Font("Verdana", 10); //Create a PrintDocument object PrintDocument pd = new PrintDocument(); //Add PrintPage event handler pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler); //Call Print Method pd.Print(); } private void PrintTextFileHandler(object sender, PrintPageEventArgs ppeArgs) { //Get the Graphics object Graphics g = ppeArgs.Graphics; float linesPerPage = 0; float yPos = 0; int count = 0; //Read margins from PrintPageEventArgs float leftMargin = ppeArgs.MarginBounds.Left; float topMargin = ppeArgs.MarginBounds.Top; string line = null; //Calculate the lines per page on the basis of the height of the page and the height of the font linesPerPage = ppeArgs.MarginBounds.Height / verdana10Font.GetHeight(g); //Now read lines one by one, using StreamReader while (count < linesPerPage && ((line = reader.ReadLine()) != null)) { //Calculate the starting position yPos = topMargin + (count * verdana10Font.GetHeight(g)); //Draw text g.DrawString(line, verdana10Font, Brushes.Black, leftMargin, yPos, new StringFormat()); //Move to next line count++; } //If PrintPageEventArgs has more pages to print if (line != null) { ppeArgs.HasMorePages = true; } else { ppeArgs.HasMorePages = false; } } private void releaseObject(object obj) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (Exception ex) { obj = null; MessageBox.Show("Unable to release the Object " + ex.ToString()); } finally { GC.Collect(); } }

What should i do to get the printer?

推荐答案

这是asp应用程序吗? 以下语句使我怀疑它是:string path = Server.MapPath("~/bin/Reciept3.rtf"); 如果这样做是从服务器端的asp应用程序进行打印,那么您需要确保asp用户可以访问打印机. 最好的问候 Espen Harlinn Is this an asp application? The following statement makes me suspect that it is: string path = Server.MapPath("~/bin/Reciept3.rtf"); If this, printing from a server side asp application, is what you are trying to do then you need to make sure that the asp user has access to the printer. Best regards Espen Harlinn

由于错误提示,请检查计算机上是否已安装打印机. 转到开始->设备和打印机,并确保至少安装了一台打印机并将其设置为默认打印机. As the error suggests, check if printers are installed on your machine. Goto Start -> Devices and printers and ensure that at least one printer is installed and set as default.

更多推荐

System.Drawing.PrinterExceptio ...

本文发布于:2023-11-12 10:59:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:System   Drawing   PrinterExceptio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!