2009-08-04 4 views
0

Ich habe eine Windows App, wo ich eine Liste von PDFs in einer Listbox an den Drucker senden möchte. Durch den folgenden Code kann ich sehen, dass * axAcroPDF1.LoadFile (s) jede Datei in meiner Anwendung lädt, aber Acrobat scheint nur das letzte Element in der lbPDFList Listbox an den Drucker zu drucken (zB wenn es 4 PDFs gibt um zu drucken, wird immer nur die letzte PDF gedruckt)?Verwenden von Acrobat Plugin zum Drucken mehrerer PDFs (axAcroPDF1)

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); 
       } 

Ist dies ein Threading-Problem?

Antwort

0

Die Antwort war einfach! Ignorieren Sie die axAcroPDF Objekt und drucken nur das Fenster mit Druckfunktion (den Code unten in einer Schleife verwenden, um jede PDF drucken):

// 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(); 
+0

MIt pd.PrinterSettings.PrinterName, was pd beziehen sich auf? – Wildhorn