我找到了答案:
代替第二种方法,将更多文件添加到第一个输入文件数组。
public static void CombineMultiplePDFs(string[] fileNames, string outFile){ // step 1: creation of a document-object document document = new document(); //create newFileStream object which will be disposed at the end using (FileStream newFileStream = new FileStream(outFile, FileMode.Create)) { // step 2: we create a writer that listens to the document PdfCopy writer = new PdfCopy(document, newFileStream ); if (writer == null) {return; } // step 3: we open the document document.Open(); foreach (string fileName in fileNames) {// we create a reader for a certain documentPdfReader reader = new PdfReader(fileName);reader.ConsolidateNamedDestinations();// step 4: we add contentfor (int i = 1; i <= reader.NumberOfPages; i++){ PdfimportedPage page = writer.GetimportedPage(reader, i); writer.AddPage(page);}PRAcroForm form = reader.AcroForm;if (form != null){ writer.CopyAcroForm(reader);}reader.Close(); } // step 5: we close the document and writer writer.Close(); document.Close(); }//disposes the newFileStream object}


