如何在C#中使用PrintDialog打印文档

Tho*_*son 5 c# printing

这是我的示例代码.但它打印的是一个空页面

            printDocument1.DocumentName = "C:\a.pbf";// PrintDocument printDocument1
            printDialog1.Document = printDocument1;
            printDialog1.AllowPrintToFile = true;
            printDialog1.AllowSelection = true;
            printDialog1.AllowSomePages = true;
            printDialog1.PrintToFile = true;
            if (printDialog1.ShowDialog() == DialogResult.OK)
                printDocument1.Print();
Run Code Online (Sandbox Code Playgroud)

这有什么不对吗?请帮我

Mar*_*ell 6

您需要处理PrintPage事件以实际提供内容; MSDN有一个完整的例子.这DocumentName纯粹是向用户展示的东西 - 它不是神奇打印的现有文件的路径.

要打印现有PDF,请查看此问题