C#将制定文件夹下的PDF文件合并成一个并输出至指定路径
/// <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");
}
最新文章
- UNITY在VS中调试
- FreeSWITCH无法读取wav文件
- 使用PYTHON实现docx文档的读写
- Matrix67大牛推荐的省选知识点
- ASP.NET MVC 站点设置.html 为起始页
- 转 iOS和android游戏纹理优化和内存优化(cocos2d-x)
- hdu 1159 Palindrome(回文串) 动态规划
- 你好,C++(14)如何描述“一个名叫陈良乔,年龄33岁,身高173厘米,体重61.5千克的男人”——3.8 用结构体类型描述复杂的事物
- CentOS下安装nginx并且升级nginx到最新版
- 【转载】MongoDB中的MapReduce 高级操作介绍
- HeartBeat源码安装
- OpenStack运维(四):OpenStack备份恢复
- 【双目备课】《学习OpenCV第18章》相机模型与标定整编
- opencv: 基本知识;
- Spring Security 用户授权原理分析
- ExtJS初探:了解 Ext Core
- CF 274D Lovely Matrix 拓扑排序,缩点 难度:2
- VS中的生成事件
- Vue生命周期函数详解
- python 正则表达式 符号及其定义
热门文章
- Docker镜像导致centos-root根分区容量爆满
- bxslider使用教程
- Nginx日志中的金矿 -- 好文收藏
- asp.net core 部署到服务器之后外网访问不了
- Java 生产者消费者模式详细分析
- awk 实用技巧
- AutoCAD开发选择----ObjectARX还是.net API(转载)
- Docker入门之常用命令
- linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words
- Mysql基础安装,初视篇