public bool Print()
{
try
{
PrintDocument docToPrint = new PrintDocument();
docToPrint.BeginPrint += DocToPrint_BeginPrint;
docToPrint.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.docToPrint_PrintPage);
//docToPrint.DefaultPageSettings.Landscape = false;
PaperSize p = null;
foreach (PaperSize ps in docToPrint.PrinterSettings.PaperSizes)
{
if (ps.PaperName.Equals("102 x 152 毫米 (4 x 6 英寸)"))
{
p = ps;
break;
}
}
docToPrint.DefaultPageSettings.PaperSize = p;
docToPrint.DefaultPageSettings.Margins = new Margins(1, 1, 1, 1);
docToPrint.DefaultPageSettings.Color = true;//是否彩色
//docToPrint.DefaultPageSettings.Landscape = true;
docToPrint.PrinterSettings.DefaultPageSettings.PaperSize = p;
docToPrint.PrinterSettings.DefaultPageSettings.Margins = new Margins(1, 1, 1, 1);
docToPrint.PrinterSettings.DefaultPageSettings.Color = true;
//System.Windows.Application.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
//printDialog.AllowSomePages = true;
//printDialog.ShowHelp = true;
//printDialog.Document = docToPrint;
//if (printDialog.ShowDialog() == DialogResult.OK)
//{
// docToPrint.Print();
//}
docToPrint.Print();
return true;
}
catch (Exception ex)
{
Log.WriteLog($"照片打印失败!异常原因:{ex.Message}");
return false;
}
}
没有这个属性可以设置纸张类型的。