tags:

views:

651

answers:

1

Hi there,

I've got a windows app where I want to send to printer a list of PDF's in a listbox. Stepping through the code below, I can see that *axAcroPDF1.LoadFile(s) is loading each file in my application, but Acrobat only seems to print the last item in the lbPDFList listbox to the printer (eg. if there is 4 PDF's to print, it will always only print the last 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);
                }

Is this a threading issue?

A: 

The answer was simple! Ignore the axAcroPDF object and just print using the windows print function (use the code below inside a loop to print each 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();
WIth pd.PrinterSettings.PrinterName, what pd refer to?
Wildhorn