/// <summary>
/// 将源路径下的PDF合并至目标路径下
/// </summary>
/// <param name="SourcePath">源路径</param>
/// <param name="TargetPath">目标路径</param>
/// <param name="NewFileName">新文件名</param>
private void MergePDF(string SourcePath,string TargetPath,string NewFileName)
{
string[] filenames = Directory.GetFiles(SourcePath, "*.pdf", SearchOption.AllDirectories);
int fileNum = filenames.Length;//pdf的个数
Dictionary<int, string> myDictionary = new Dictionary<int, string>();
if (fileNum < 2)
{
return;//源路径下只有一个PDF文件,那么不合并
}
Aspose.Pdf.Document a = new Document();
foreach (var file in filenames)//遍历源路径,获取该路径下所有PDF文件的path
{
Document b = new Document(file);
foreach (Page item in b.Pages)
{
a.Pages.Add(item);
}
a.Save(TargetPath + "\\" + NewFileName);
}
}

//调用,这里使用了Aspose.Pdf.dll

using Aspose.Pdf;
using System.IO;

private void button1_Click(object sender, EventArgs e)
{
string path_Source=@"C:\Users\Evan\Documents\PDF 文件\AutoSave";
string path_Target=Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//计算机桌面的路径
MergePDF(path_Source, path_Target,"666666.pdf");
}

最新文章

  1. UNITY在VS中调试
  2. FreeSWITCH无法读取wav文件
  3. 使用PYTHON实现docx文档的读写
  4. Matrix67大牛推荐的省选知识点
  5. ASP.NET MVC 站点设置.html 为起始页
  6. 转 iOS和android游戏纹理优化和内存优化(cocos2d-x)
  7. hdu 1159 Palindrome(回文串) 动态规划
  8. 你好,C++(14)如何描述“一个名叫陈良乔,年龄33岁,身高173厘米,体重61.5千克的男人”——3.8 用结构体类型描述复杂的事物
  9. CentOS下安装nginx并且升级nginx到最新版
  10. 【转载】MongoDB中的MapReduce 高级操作介绍
  11. HeartBeat源码安装
  12. OpenStack运维(四):OpenStack备份恢复
  13. 【双目备课】《学习OpenCV第18章》相机模型与标定整编
  14. opencv: 基本知识;
  15. Spring Security 用户授权原理分析
  16. ExtJS初探:了解 Ext Core
  17. CF 274D Lovely Matrix 拓扑排序,缩点 难度:2
  18. VS中的生成事件
  19. Vue生命周期函数详解
  20. python 正则表达式 符号及其定义

热门文章

  1. Docker镜像导致centos-root根分区容量爆满
  2. bxslider使用教程
  3. Nginx日志中的金矿 -- 好文收藏
  4. asp.net core 部署到服务器之后外网访问不了
  5. Java 生产者消费者模式详细分析
  6. awk 实用技巧
  7. AutoCAD开发选择----ObjectARX还是.net API(转载)
  8. Docker入门之常用命令
  9. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words
  10. Mysql基础安装,初视篇