Использование плагина Acrobat для печати нескольких PDF-файлов (axAcroPDF1) - PullRequest
0 голосов
/ 04 августа 2009

У меня есть приложение для 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);
                }

Это проблема с потоками?

1 Ответ

0 голосов
/ 11 августа 2009

Ответ был прост! Игнорируйте объект 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();
...