我想用c#打印一份文件。但我的打印机间连接,我想用phografer纸打印,但我想打印A4普通纸

时间:2015-06-26 13:10:13

标签: c# printing

//Button print

printPreviewDialog1.Document = printDocument1;
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
DialogResult result = printPreviewDialog1.ShowDialog();
if (result==DialogResult.OK)
{
    printDocument1.Print ();
}


private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

e.Graphics.DrawString("Nome Equipamento:  ", new Font("Arial", 12), Brushes.Black, new Point(25, 210));

e.Graphics.DrawString(comboBox1.Text, new Font("Arial", 12), Brushes.Black, new Point(25, 250));

1 个答案:

答案 0 :(得分:0)

尝试这样的事情。我只是在没有测试的情况下将其破解,并且我没有添加错误处理代码。它假定您的打印机支持打印A4。但你应该明白这一点。

        PaperSize search;
        foreach (PaperSize item in printDocument1.PrinterSettings.PaperSizes)
        {
            if (item.Kind == PaperKind.A4)
            {
                search = item;
                break;
            }
        }

        printDocument1.DefaultPageSettings.PaperSize = search;
        printDocument1.Print();

或者,您可以创建自己的纸张尺寸:

        printDocument.DefaultPageSettings.PaperSize = 
                new PaperSize("My A4", A4width, A4height);