[点晴永久免费OA]C#指定打印机打印
当前位置:点晴教程→点晴OA办公管理信息系统
→『 经验分享&问题答疑 』
1.
public bool Print(string _paperName, decimal _width, decimal _height, string _fpdm) 2.
{ 3.
lock (_doPrint) 4.
{ 5.
try 6.
{ 7.
//获取打印尺寸 8.
GetInvoiceSize(ConnStr, _fpdm); 9.
System.Drawing.Printing.PrintDocument
printDoc = new
System.Drawing.Printing.PrintDocument(); 10. PrintController
printController = new
StandardPrintController(); 11. printDoc.PrintController =
printController; 12. int pWidth = Tools.ToInt(_width *
Convert.ToDecimal(inchToMM)); //转换成百分之一英寸 13. int pHeight = Tools.ToInt(_height *
Convert.ToDecimal(inchToMM)); 14. bool isFind = false; 15. //遍历打印机 16. foreach (string pName in PrinterSettings.InstalledPrinters) 17. { 18. if (PrinterName.Trim().ToUpper() ==
pName.Trim().ToUpper()) 19. { 20.
printDoc.PrinterSettings.PrinterName
= PrinterName; 21. isFind = true; 22. break; 23. } 24. } 25. if (isFind == false) 26. { 27. MessageBox.Show("未找到名为\'" + PrinterName.Trim().ToUpper() + "\'的打印机!", "提醒", MessageBoxButtons.OK,
MessageBoxIcon.Warning); 28. return false; 29. } 30. 31. //遍历纸张 32. foreach (PaperSize paperSize in printDoc.PrinterSettings.PaperSizes) 33. { 34. if (paperSize.PaperName.ToUpper() ==
PaperName.ToUpper()) 35. { 36.
printDoc.DefaultPageSettings.PaperSize = paperSize; 37. break; 38. } 39. } 40. 41. //
printDoc.DefaultPageSettings.PaperSize = new PaperSize(); 42. printDoc.OriginAtMargins = true; 43.
printDoc.DefaultPageSettings.Margins
= new Margins(0, 0, 0, 0); 44. printDoc.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); 45. printDoc.Print(); 46. return true; 47. } 48. catch (Exception ex) 49. { 50.
Tools.SaveErrLog(ex.Message, "PrinterPzb_Print"); 51. return false; 52. } 53. } 54.
}
该文章在 2022/7/2 12:19:15 编辑过 |
关键字查询
相关文章
正在查询... |