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. ASP.NET知识总结(2.对比Get和Post提交方式)

    2.对比Get和Post提交方式 get:<1>在地址栏中通过?key1=value1&key2=value2...的方式传值 <2>传递的数据用户可以直接在url中看 ...

  2. iOS 禁止边缘滑动返回

    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

  3. C++ 基础知识复习(三)

    43. 继承的几种方式: 答:共有继承public,保护继承protected,私有继承private.其中后两种继承会改变原有的访问级别. 44. 深复制与浅复制: 答:简单理解,深复制自己申请了内 ...

  4. 最短路径—Dijkstra算法和Floyd算法

    原文链接:http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html 最后边附有我根据文中Dijkstra算法的描述使用jav ...

  5. react native TextInput

    今天我想说一下react native中的一个控件,TextInput 翻译过来就是文本输入,对应着android中的EditText.我们先看一下官方是怎样描述的.TextInput是一个允许用户在 ...

  6. android 多媒体数据库详解(转)

    转自:http://www.2cto.com/kf/201309/242876.html 主要分为几节: 1. Android的媒体文件内部是如何存储的? 2. Andoid的媒体文件如何获取? 3. ...

  7. 基于UDP协议的socket编程示例

    客户端 import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; impo ...

  8. c#使用多线程的几种方式示例详解

    本文转载自:http://www.jb51.net/article/46234.htm 本文章主要介绍了c#使用多线程的几种方式,通过示例学习c#的多线程使用方式,大家参考使用吧 (1)不需要传递参数 ...

  9. springboot与shiro配置

    详情参考:  http://blog.csdn.net/catoop/article/details/50520958 http://blog.csdn.net/qiuqiupeng/article/ ...

  10. [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点

    Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...