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 = ; i < fileList.Length; i++)
{
if (!string.IsNullOrEmpty(fileList[i]))
{
PdfReader reader = new PdfReader(fileList[i]);
int iPageNum = reader.NumberOfPages;
for (int j = ; j <= iPageNum; j++)
{
document.NewPage();
newPage = writer.GetImportedPage(reader, j);
cb.AddTemplate(newPage, , );
}
readerList.Add(reader);
}
}
document.Close();
//释放集合资源
foreach (var rd in readerList)
{
rd.Close();
}
}
}

iTextSharpH的更多相关文章

随机推荐

  1. 指令创建 Express Node.js 项目

    1.安装 Express 1.1 安装 Express 框架 首先保证已经安装过了 Node.js,然后进入终端使用管理员身份来安装 Express 框架. # 安装 express $ sudo n ...

  2. zsh+on-my-zsh配置教程指南(程序员必备)

    本文以CentOS 7/Mac 为例,介绍zsh的配置使用教程. 准备 查看当前环境shell echo $SHELL <!-- more --> 查看系统自带哪些shell cat /e ...

  3. Win10 calc.exe 无法打开计算器的解决方法

    先将所有程序关闭,以管理员身份运行 Windows PowerShell,之后输入以下命令 Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage - ...

  4. 根据IP查地理位置信息

    IP地址库下载地址: https://www.ipip.net/product/ip.html 使用方式(Python): https://github.com/ipipdotnet/datx-pyt ...

  5. 开始学习Functional Programming

    打算先学F#, 再学Scala. 第一个F#程序 open System [<EntryPoint>] let main argv = let a = "Hello, World ...

  6. Win10系统安装UEFI+GPT配置

    借鉴博文  https://blog.csdn.net/lyj_viviani/article/details/51800445   安装win10需要改用UEFI引导模式,硬盘需要换成GUID格式; ...

  7. spring boot+mybatis+mysql

    spring boot整合mybatis,曾经的几个小困惑和踩的坑. 一.mybatis的结构 mybatis和spring boot的整合,网上无数的教程,都是教你一步步集成,照着做没问题,但做下来 ...

  8. ROS工作空间和程序包创建

    预备工作后面操作中我们将会用到ros-tutorials程序包,请先安装: $ sudo apt-get install ros-<distro>-ros-tutorials 将 < ...

  9. react文档demo实现输入展示搜索结果列表

    文档页面地址:https://doc.react-china.org/docs/thinking-in-react.html 该文档只给了具体实现思路,下面是我实现的代码. 初学react,如果有写的 ...

  10. Linux下Qt Creator编辑器无法输入中文解决

    Ubuntu安装了搜狗输入法,在浏览器中可以使用,但是在Qt Creator中却无法输入中文. 解决办法: 执行sudo apt-get install fcitx-libs-qt5 该命令将库文件l ...