zoukankan      html  css  js  c++  java
  • iTextSharpH

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.IO;
    
    
    public class iTextSharpH
    {
        /// <summary> 合并PDF </summary>
        /// <param name="fileList">PDF文件集合</param>
        /// <param name="outMergeFile">合并文件名</param>
        public static void MergePDFFiles(string[] fileList, string outMergeFile)
        {
            List<PdfReader> readerList = new List<PdfReader>();//记录合并PDF集合
            Document document = new Document();
            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();
            //释放集合资源
            foreach (var rd in readerList)
            {
                rd.Close();
            }
        }
    }
  • 相关阅读:
    java中 == 与equals 的区别
    java中的多线程 // 基础
    MySQL-锁机制
    将博客搬至CSDN
    MySQL-事务
    MySQL-存储过程
    MySQL-触发器
    MySQL-视图
    Redis设置Auth认证保护
    PHP目前常见的五大运行模式
  • 原文地址:https://www.cnblogs.com/lee2011/p/9355149.html
Copyright © 2011-2022 走看看