2009-08-04 7 views
0

J'ai une application Windows où je veux envoyer à l'imprimante une liste de PDF dans une liste. En parcourant le code ci-dessous, je peux voir que * axAcroPDF1.LoadFile (s) charge chaque fichier dans mon application, mais Acrobat semble seulement imprimer le dernier élément dans la liste lbPDFList à l'imprimante (par exemple s'il y a 4 PDF pour imprimer, il n'imprimera toujours que le dernier PDF)?Utiliser Acrobat Plugin pour imprimer plusieurs PDF (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); 
       } 

Est-ce un problème de threading?

Répondre

0

La réponse était simple! Ignorer l'objet axAcroPDF et juste imprimer en utilisant la fonction d'impression Windows (utilisez le code ci-dessous dans une boucle pour imprimer chaque 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(); 
+0

aveC pd.PrinterSettings.PrinterName, ce pd référence? – Wildhorn

Questions connexes