[點晴永久免費OA]C#指定打印機打印
當(dāng)前位置:點晴教程→點晴OA辦公管理信息系統(tǒng)
→『 經(jīng)驗分享&問題答疑 』
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)); //轉(zhuǎn)換成百分之一英寸 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 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |