After iTextSharp merges PDF files, you cannot delete a single merged file,
Private void MergePDFFiles (string [] fileList, string outMergeFile) {List <PdfReader> readerList = new List <PdfReader> (); // record merge PDF set iTextSharp. text. document document = new iTextSharp. text. document (iTextSharp. text. pageSize. a4.Rotate (); analyze writer = analyze writer. getInstance (document, new FileStream (outMergeFile, FileMode. create); document. open (); Response contentbyte cb = writer. directContent; PdfImpo RtedPage newPage; for (int I = 0; I <fileList. Length; I ++) {if (! String. isNullOrEmpty (fileList [I]) {PdfReader reader = new PdfReader (fileList [I]); int iPageNum = reader. numberOfPages; for (int j = 1; j <= iPageNum; j ++) {document. newPage (); newPage = writer. getImportedPage (reader, j); cb. addTemplate (newPage, 0, 0);} readerList. add (reader) ;}} document. close ();
1 foreach (var rd in readerList) 2 { 3 rd.Dispose(); 4 }
The key point of http://blog.csdn.net/hebbers/article/details/70332015 lies in
PdfReader is released cyclically. When a local variable is defined, the reference cannot be released independently and must be released cyclically.
List<PdfReader> readerList = new List<PdfReader>();
foreach (var rd in readerList) { rd.Dispose(); }