我有一个Windows应用程序,我想在列表框中向打印机发送PDF列表。 单步执行下面的代码,我可以看到* axAcroPDF1.LoadFile(s)正在加载我的应用程序中的每个文件,但Acrobat似乎只将lbPDFList列表框中的最后一项打印到打印机(例如,如果有4个PDF到打印,它将始终只打印最后的PDF)?
int iListCounter = lbPDFList.Items.Count;
for (int i=0; i < iListCounter; i++)
{
String s = null;
lbPDFList.SetSelected(i,true);
s = lbPDFList.SelectedItem.ToString();
axAcroPDF1.LoadFile(s);
axAcroPDF1.Show();
axAcroPDF1.printAllFit(true);
}
这是一个线程问题吗?
答案 0 :(得分:0)
答案很简单!忽略axAcroPDF对象,只使用windows打印功能进行打印(使用循环内部的代码打印每个PDF):
// start a new cmd process
Process objP = new Process();
objP.StartInfo.FileName = strFilePath;
objP.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.
//!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file.
//The action in our case is to "Print" a file in a selected printer.
//!! Print the document in the printer selected in the PrintDialog !!//
objP.StartInfo.Verb = "printto";
objP.StartInfo.Arguments = "/p /h \"" + strFilePath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";//pd.PrinterSettings.PrinterName;
objP.StartInfo.CreateNoWindow = true; //!! Don't create a Window.
objP.Start(); //!! Start the process !!//
objP.CloseMainWindow();