How to print a document using PrintDialog in C#

放肆的年华 提交于 2019-12-22 07:10:13

问题


Here is my Sample code . But its printing an Empty page

            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();

Whats wrong with this?. Please help me


回答1:


You need to handle the PrintPage event to actually provide the contents; MSDN has a full example. The DocumentName is purely something to show to the user - it is not the path of an existing file to magically print.

For printing an existing PDF, maybe look at this question



来源:https://stackoverflow.com/questions/4253564/how-to-print-a-document-using-printdialog-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!