这是我的示例代码。但它打印一个空页
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();
这有什么不对吗?请帮帮我
答案 0 :(得分:6)
您需要处理PrintPage
事件以实际提供内容; MSDN有一个full example。 DocumentName
纯粹是向用户显示的内容 - 不现有文件的神奇打印路径。
要打印现有PDF,请查看this question
答案 1 :(得分:0)
这样做:
public static void PrintToASpecificPirnter()
{
using (PrintDialog printDialog=new PrintDialog ())
{
printDialog.AllowSomePages = true;
printDialog.AllowSelection = true;
if (printDialog.ShowDialog() == DialogResult.OK)
{
var StartInfo = new ProcessStartInfo();
StartInfo.CreateNoWindow = true;
StartInfo.UseShellExecute = true;
StartInfo.Verb = "printTo";
StartInfo.Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"";
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.FileName = fileName;
Process.Start(StartInfo);
}
}
}