public bool Print(string _paperName, decimal _width, decimal _height, string _fpdm)
{
lock (_doPrint)
{
try
{
//获取打印尺寸
GetInvoiceSize(ConnStr, _fpdm);
System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
PrintController printController = new StandardPrintController();
printDoc.PrintController = printController;
int pWidth = Tools.ToInt(_width * Convert.ToDecimal(inchToMM)); //转换成百分之一英寸
int pHeight = Tools.ToInt(_height * Convert.ToDecimal(inchToMM));
bool isFind = false;
//遍历打印机
foreach (string pName in PrinterSettings.InstalledPrinters)
{
if (PrinterName.Trim().ToUpper() == pName.Trim().ToUpper())
{
printDoc.PrinterSettings.PrinterName = PrinterName;
isFind = true;
break;
}
}
if (isFind == false)
{
MessageBox.Show("未找到名为\'" + PrinterName.Trim().ToUpper() + "\'的打印机!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
//遍历纸张
foreach (PaperSize paperSize in printDoc.PrinterSettings.PaperSizes)
{
if (paperSize.PaperName.ToUpper() == PaperName.ToUpper())
{
printDoc.DefaultPageSettings.PaperSize = paperSize;
break;
}
}
// printDoc.DefaultPageSettings.PaperSize = new PaperSize();
printDoc.OriginAtMargins = true;
printDoc.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage);
printDoc.Print();
return true;
}
catch (Exception ex)
{
Tools.SaveErrLog(ex.Message, "PrinterPzb_Print");
return false;
}
}
}