标签:gen 完全 .net efi pdf logs mode .text sdn
private void MergePDFFiles(string[] fileList, string outMergeFile) { List<PdfReader> readerList = new List<PdfReader>();//记录合并PDF集合 iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate()); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outMergeFile, FileMode.Create)); document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage 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 }
原文链接:http://blog.csdn.net/hebbers/article/details/70332015 关键点在与
PdfReader的循环释放,定义局部变量后独立释放引用并不能完全释放,需要单独循环释放。
List<PdfReader> readerList = new List<PdfReader>();
foreach (var rd in readerList)
{
rd.Dispose();
}
iTextSharp 合并PDF后,无法删除已经合并的单个文件
标签:gen 完全 .net efi pdf logs mode .text sdn
原文地址:http://www.cnblogs.com/xiaojt/p/6859833.html