zoukankan      html  css  js  c++  java
  • iTextSharp 合并PDF后,无法删除已经合并的单个文件

     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();  
                 }  
  • 相关阅读:
    笔试助攻题(思路)
    const 修饰成员函数 前后用法(effective c++ 03)
    UNIX 是啥?!和Linux什么关系?
    我的offer之路(一)
    我的offer之路(一)
    ANSI C 与 K&R C
    c内置数据类型
    预处理器
    小数用二进制如何表示
    C++中有三种创建对象的方法
  • 原文地址:https://www.cnblogs.com/xiaojt/p/6859833.html
Copyright © 2011-2022 走看看