1.引用iTextSharp,用于拆分和合并pdf文件

using iTextSharp.text;
using iTextSharp.text.pdf;

2.合并pdf

 //outMergeFile是pdf文件合并后的输出路径
//lstFile里存放要进行合并的pdf文件的路径
public static void mergePDFFiles(string outMergeFile, List<string> lstFile)
{ if (!Sql.IsEmptyString(outMergeFile))
{
try
{
PdfReader reader;
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath(outMergeFile), FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage newPage;
for (int i = ; i < lstFile.Count; i++)
{
string newpath = lstFile[i];
reader = new PdfReader(newpath);
int iPageNum = reader.NumberOfPages;
int startPage = ;
int rotation;
while (startPage <= iPageNum)
{
document.SetPageSize(reader.GetPageSizeWithRotation(startPage));
document.NewPage();
newPage = writer.GetImportedPage(reader, startPage);
rotation = reader.GetPageRotation(startPage);//获取每一页pdf文件的rotation
                  //根据每一页的rotation重置宽高,否则都按首页宽高合并可能会造成信息丢失
if (rotation == )
{
cb.AddTemplate(newPage, , -1f, 1f, , , reader.GetPageSizeWithRotation(startPage).Height);
}
else if (rotation == )
{
cb.AddTemplate(newPage, -1f, , , -1f, reader.GetPageSizeWithRotation(startPage).Width, reader.GetPageSizeWithRotation(startPage).Height);
}
else if (rotation == )
{
cb.AddTemplate(newPage, , 1f, -1f, , reader.GetPageSizeWithRotation(startPage).Width, );
}
else
{
cb.AddTemplate(newPage, 1f, , , 1f, , );
}
startPage++;
}
}
document.Close();
}
catch (Exception ex)
{
outMergeFile = string.Empty;
SplendidError.SystemError(new StackTrace(true).GetFrame(), ex);
}
}
}

3.pdf拆分


注:              string[] sPages = sSplitText.Split(',');
List<int> list = new List<int>();
foreach (string val in sPages)
{
list.Add(Sql.ToInteger(val));
}
private void SplitPdf(byte[] imageCONTENT, string sImagePath, List<int> list)
{
PdfReader reader = new PdfReader(imageCONTENT);
FileStream outFileStream = new FileStream(sImagePath, FileMode.Create);
Document destinationDoc = null;
PdfCopy pdfCopy = null;
destinationDoc = new Document();
pdfCopy = new PdfCopy(destinationDoc, outFileStream);
destinationDoc.Open();
if (list.Count > )
{
int pageArrayIndex = ;
while (pageArrayIndex < list.Count)
{
destinationDoc.SetPageSize(reader.GetPageSizeWithRotation(list[pageArrayIndex]));
destinationDoc.NewPage();
pdfCopy.AddPage(pdfCopy.GetImportedPage(reader, list[pageArrayIndex]));
pageArrayIndex++;
}
}
destinationDoc.Close();
destinationDoc.Dispose();
destinationDoc = null;
}

pdf拆分与合并的更多相关文章

  1. PDF 拆分/合并

    不会真的有人会去下载那些广告免费,实则要收会员费的黑心软件来进行PDF的拆分合并吧??? 在下载两个均不能免费实现PDF自由拆分.合并,以及PDF打印方式会增加文件大小的情况下,一个合格的程序员肯定不 ...

  2. fasta文件拆分与合并

    Linux中fasta文件的拆分与合并 FASTA文件的拆分: (1)如果从一个文件a提取第11至20个序列存到另一个文件b: awk -v RS='>' 'NR>1{i++}i>= ...

  3. Goldengate进程的拆分与合并

    Goldengate的拆分与合并分类: ORACLE GoldenGate 2013-10-10 15:22 721人阅读 评论(0) 收藏 举报在使用Goldengate作为复制解决方案时,随着负载 ...

  4. C#文件的拆分与合并操作示例

    C#文件的拆分与合并操作示例代码. 全局变量定义 ;//文件大小 //拆分.合并的文件数 int count; FileInfo splitFile; string splitFliePath; Fi ...

  5. (Sql Server)数据的拆分和合并

    (Sql Server)数据的拆分和合并 背景: 今天遇到了数据合并和拆分的问题,尝试了几种写法.但大致可分为两类:一.原始写法.二.Sql Server 2005之后支持的写法.第一种写法复杂而且效 ...

  6. NDK学习笔记-文件的拆分与合并

    文件的拆分与合并在开发中经常会用到,上传或是下载的时候都有这样的运用 文件拆分的思路 将文件大小拆分为n个文件 那么,每个文件的大小就是等大小的 如果文件大小被n除不尽,那么就使用n+1个文件来拆分 ...

  7. spss-数据抽取-拆分与合并

    spss-数据抽取-拆分与合并 数据抽取也成为数据拆分,是指保留.抽取原数据表中某些字段.记录的部分信息,形成一个新字段.新纪录.分为:字段拆分和随机抽样两种方法. 一:字段拆分 如何提取" ...

  8. 【BIM】基于BIMFACE的空间拆分与合并

    BIMFACE中矩形空间拆分与合并 应用场景 在BIM运维场景中,空间同设备一样,作为一种资产被纳入运维管理体系,典型的应用场景例如商铺.防火分区等,这就涉及到空间的拆分和合并,在bimface中,已 ...

  9. fastq-to-fasta转换及fasta拆分、合并

    格式转换: use awk :awk 'BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++ ...

随机推荐

  1. c语言中->(间接成员运算符)的含义

    写于2016年12月12日. "->"称为间接成员运算符. 总体注解:这个运算符与指向结构(sturct)或联合(union)的指针一起使用,用来指明结构或联合的的成员.假设 ...

  2. Spring MVC基础入门

    Spring MVC简介 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱 ...

  3. [Unity3D插件]2dToolKit系列三 碰撞检测功能的实现以及障碍物的随机摆放

    貌似有一段时间没更新2dtoolkit系列了,这段时间一直在忙着其他事情,今天开始继续这个插件系列的教程,网上搜索,貌似关于这个插件的教程无非还是跟官方的教程很类似,有的甚至都没有自己照着亲手实践一遍 ...

  4. iOS ARC 下的单例模式

    #import <Foundation/Foundation.h> @interface RYSingleExample : NSObject<NSCopying> +(ins ...

  5. 【SSM】Eclipse使用Maven创建Web项目+整合SSM框架

    自己接触ssm框架有一段时间了,从最早的接触新版ITOO项目的(SSM/H+Dobbu zk),再到自己近期来学习到的<淘淘商城>一个ssm框架的电商项目.用过,但是还真的没有自己搭建过, ...

  6. Windows Server 2008 R2 配置AD(Active Directory)域控制器

    实施过程: 一.安装Windows Server2008 R2操作系统 (过程略) 二.安装域控制器 1. 修改电脑名称 2.修改电脑DNS 三.配置AD 1.在"服务器管理器"- ...

  7. 2016 Multi-University Training Contest 1 H.Shell Necklace

    Shell Necklace Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. Leetcode Word Ladder

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  9. C语言_第三章

    1.常量        1.整型常量        2.实型常量                1.十进制小数形式,由数字和小数点组成.                2.指数形式(以E或e代表以10 ...

  10. 第一章-第二题Unity3D游戏引擎相关--By林培文

    1) 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的?  他们的目标都是盈利么?  他们的目标都是赚取用户的现金么?还是别的? 2004年,Unity3D诞生于丹麦哥本 ...