首页 新闻 搜索 专区 学院

请问如何在WPF或WinFORM下在后台设置纸张类型

0
悬赏园豆:50 [待解决问题]

jobroon的主页 jobroon | 初学一级 | 园豆:157
提问于:2020-09-01 14:31
< >
分享
所有回答(1)
0
猝不及防 | 园豆:2003 (老鸟四级) | 2020-09-01 15:22

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;
        }

    }

没有这个属性可以设置纸张类型的。

支持(0) 反对(0) jobroon | 园豆:157 (初学一级) | 2020-09-01 16:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册