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. Centos7设置IP为固定值

    1.进入到系统的IP地址保存文件所在目录 [root@localhost ~]# cd /etc/sysconfig/network-scripts 2.修改保存IP信息的文件 [root@local ...

  2. Windows下安装Redis

    1.首先,Redis官方是支持Linux系统的,我这里不多说,需要的可以参考:http://www.oschina.net/question/12_18065/ 2.Windows 64位下载地址:h ...

  3. EXPORT_SYMBOL的使用

    转自:http://blog.csdn.net/cailiwei712/article/details/7998525 在查看内核驱动代码的时候会经常看到在一些函数后面总会跟EXPORT_SYMBOL ...

  4. Pyqt5 获取命令行参数sys.argv

    大家有没有注意到,很多软件都能接收第三方应用触发命令行参数,根据参数打开想要的效果. 在windows任务管理器调取命令行列,我们同样能看到进程中有好多是带有参数的. 现在,我们用Pyqt5 (Py3 ...

  5. MEF Parts Sample

    namespace Microshaoft.MEF.Contracts { using System; public delegate void ExceptionEventHandler<TS ...

  6. SourceTree安装教程和GitLab配置详解

    一.安装Git 链接: http://pan.baidu.com/s/1mh7rICK 密码: 48dj 二.安装SourceTree 链接: http://pan.baidu.com/s/1skWk ...

  7. 分配问题与Hungarian算法

    分配问题与Hungarian算法 分配问题 指派问题 匈牙利算法 匈牙利方法是一种能够在多项式时间内解决分配问题(assignment problem)的组合优化算法.它由Harold Kuhn 与1 ...

  8. 【Oracle】oracle10g以后利用q-quote特性简化包含单引号后双引号的字符串写法

    The Q-quote delimiter can be any single- or multibyte character except space, tab, and return. If th ...

  9. 1.0 UIApplication对象

    本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书”   UIApplication对象特点: 特点1: UIApplication对象是应用程 ...

  10. 基于淘宝弹性布局方案lib-flexible的问题研究

    上篇文章<淘宝弹性布局方案lib-flexible实践>结合一个简单的实例,说明了lib-flexible的基本用法,但是lib-flexible的这种适配方式在适配的时候会修改viewp ...