C# 操作打印机
2021-01-02 15:28
标签:open 使用 settings ring add tar int inter string 获取当前设置能使用的打印机: 获取打印机下的纸盒: 打印图片方法: 注册打印方法: C# 操作打印机 标签:open 使用 settings ring add tar int inter string 原文地址:https://www.cnblogs.com/rolayblog/p/14207482.html1 foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
2 {
3 prints.Add(sPrint);
4 }
1 PrinterSettings ps = new PrinterSettings();
2 ps.PrinterName = printName;
3 for (int i = 0; i )
4 {
5 sources.Add(ps.PaperSources[i].SourceName);
6 }
1 private static void PicturePrintDocument_PrintPage(object sender, PrintPageEventArgs e)
2 {
3 FileStream fs = File.OpenRead(filePath);
4 int filelength = 0;
5 filelength = (int)fs.Length; //获得文件长度
6 Byte[] image = new Byte[filelength]; //建立一个字节数组
7 fs.Read(image, 0, filelength); //按字节流读取
8 Image result = Image.FromStream(fs);
9 fs.Close();
10 e.Graphics.DrawImage(result, 0, 0); //img大小
11 //e.Graphics.DrawString(TicCode, DrawFont, brush, 600, 600); //绘制字符串
12 e.HasMorePages = false;
13 }
1 using (PrintDocument pd = new PrintDocument()) {
2 pd.PrintPage += PicturePrintDocument_PrintPage; //注册打印事件
3 pd.PrinterSettings.PrinterName = printName; //打印机选择
4 pd.Print();
5 pd.Dispose();
6 }