C#设置默认PrintDocument大小

时间:2016-12-18 03:12:24

标签: c#

如何将默认纸张尺寸设置为6英寸X 3英寸。我尝试了以下代码,但打印A4。

 private void button2_Click(object sender, EventArgs e)
        {

            try
            {
                PrintDocument pd = new PrintDocument();

                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                PaperSize ps = new PaperSize("Custom", 440, 220);
                pd.DefaultPageSettings.PaperSize = ps;
                PageSettings pa = new PageSettings();
                pa.Margins = new Margins(0, 0, 0, 0);
                pd.DefaultPageSettings.Margins = pa.Margins;
                pd.Print();
            }
            catch (Exception ex)
            {
               MessageBox.Show("Error: " + ex.ToString());
           // Response.Write("Error: " + ex.ToString());
            }
        }

1 个答案:

答案 0 :(得分:0)

您可以从以下文章中使用PrinterSettings课程: https://www.codeproject.com/articles/6899/changing-printer-settings-using-c

PrintDocument.PrinterSettings会从打印机中为您提供可用的纸张尺寸。

请参阅以下链接:

Change printer default paper size