0

我有一个 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);
                }

这是线程问题吗?

4

1 回答 1

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();
于 2009-08-11T06:18:56.097 回答