如何打印在C#中使用PrintDialog类的文档 [英] How to print a document using PrintDialog in C#
本文介绍了如何打印在C#中使用PrintDialog类的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的示例代码。但其打印空白页
printDocument1.DocumentName =C:\a.pbf; // PrintDocument的printDocument1
printDialog1.Document = printDocument1;
printDialog1.AllowPrintToFile = TRUE;
printDialog1.AllowSelection = TRUE;
printDialog1.AllowSomePages = TRUE;
printDialog1.PrintToFile = TRUE;
如果(printDialog1.ShowDialog()== DialogResult.OK)
printDocument1.Print();
请告诉我不对的?请帮我。
解决方案
您需要处理的 的PrintPage
事件实际提供的内容; MSDN有一个完整的例子。该 DocumentName
是纯粹的东西展现给用户 - 它的不的现有文件的路径为神奇打印
<。 p>有关打印现有的PDF,也许看这个问题一>
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
解决方案
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
这篇关于如何打印在C#中使用PrintDialog类的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文