当前位置:网站首页>C#/VB.NET 合并PDF文档
C#/VB.NET 合并PDF文档
2022-07-01 15:32:00 【InfoQ】
将多个PDF合并为一个PDF文档
- 获取要合并的文档的路径并将它们存储在字符串数组中。
- 调用PdfDocument.MergeFiles()方法合并文档。
- 用PdfDocumentBase.Save()方法另存为一个PDF文档
using System;
using Spire.Pdf;
namespace MergePDFs
{
class Program
{
static void Main(string[] args)
{
//获取要合并的文档的路径
String[] files = new String[] {
"Sample.pdf",
"Sample1.pdf",
"Samplex.pdf"
//合并文档
PdfDocumentBase doc = PdfDocument.MergeFiles(files);
//将结果保存到 PDF文件
doc.Save("MergeDocuments.pdf", FileFormat.PDF);
}
}
}Imports System
Imports Spire.Pdf
Namespace MergePDFs
Class Program
Private Shared Sub Main(ByVal args() As String)
'获取要合并的文档的路径
Dim files() As String = New String() {" Sample.pdf", "Sample-1.pdf", "Samplex.pdf"}
'合并文档
Dim doc As PdfDocumentBase = PdfDocument.MergeFiles(files)
'将结果保存到 PDF文件
doc.Save("output.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
将不同 PDF的指定页面合并为一个 PDF文档
- 获取源文档的路径并将它们存储在字符串数组中。
- 创建一个 PdfDocument 数组,并将每个源文档加载到单独的 PdfDocument 对象。
- 使用PdfDocument.InsertPage() 方法和 PdfDocument.InsertPageRange() 方法将源文档的指定页面插入到新文档中。
- 用PdfDocument.SaveToFile()方法将新文档保存为PDF。
using System;
using Spire.Pdf;
namespace MergeSelectedPages
{
class Program
{
static void Main(string[] args)
{
//获取要合并的文档的路径
String[] files = new String[] {
"Sample1.pdf",
"Sample.pdf",
"Sample2.pdf"};
//创建一个 PdfDocument 数组
PdfDocument[] docs = new PdfDocument[files.Length];
//循环浏览文档
for (int i = 0; i < files.Length; i++)
{
//加载指定文档
docs[i] = new PdfDocument(files[i]);
}
//创建一个 PdfDocument 对象以生成新的 PDF 文档
PdfDocument doc = new PdfDocument();
//将不同文档中的指定页面插入到新文档中
doc.InsertPage(docs[0], 0);
doc.InsertPageRange(docs[1], 0, 2);
doc.InsertPage(docs[2], 1);
//保存文档为PDF文件
doc.SaveToFile("output.pdf");
}
}
}Imports System
Imports Spire.Pdf
Namespace MergeSelectedPages
Class Program
Private Shared Sub Main(ByVal args() As String)
'获取要合并的文档的路径
Dim files() As String = New String() {"Sample1.pdf", "Sample.pdf", "Sample2.pdf"}
'创建一个 PdfDocument 数组
Dim docs() As PdfDocument = New PdfDocument((files.Length) - 1) {}
'循环浏览文档
Dim i As Integer = 0
Do While (i < files.Length)
'加载指定文档
docs(i) = New PdfDocument(files(i))
i = (i + 1)
Loop
'创建一个 PdfDocument 对象以生成新的 PDF 文档
Dim doc As PdfDocument = New PdfDocument
'将不同文档中的指定页面插入到新文档中
doc.InsertPage(docs(0), 0)
doc.InsertPageRange(docs(1), 0, 2)
doc.InsertPage(docs(2), 1)
'保存文档为PDF文件
doc.SaveToFile("output.pdf")
End Sub
End Class
End Namespace
边栏推荐
- Tableapi & SQL and MySQL grouping statistics of Flink
- [Cloudera][ImpalaJDBCDriver](500164)Error initialized or created transport for authentication
- Survey of intrusion detection systems:techniques, datasets and challenges
- ThinkPHP进阶
- 【一天学awk】条件与循环
- Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching
- 项目中字符串判空总结
- [antenna] [3] some shortcut keys of CST
- [advanced ROS] lesson 5 TF coordinate transformation in ROS
- 微信小程序03-文字一左一右显示,行内块元素居中
猜你喜欢
![opencv学习笔记六--图像特征[harris+SIFT]+特征匹配](/img/50/5c8adacea78e470c255070c8621ddd.png)
opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
![[target tracking] |stark](/img/e2/83e9d97cfb8c49cfb8d912cfe2f858.png)
[target tracking] |stark

【STM32学习】 基于STM32 USB存储设备的w25qxx自动判断容量检测

Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
![[advanced ROS] lesson 5 TF coordinate transformation in ROS](/img/4d/ae7d477bf6928005e16f046d461dcb.png)
[advanced ROS] lesson 5 TF coordinate transformation in ROS

Junda technology indoor air environment monitoring terminal PM2.5, temperature and humidity TVOC and other multi parameter monitoring
SQL常用的四个排序函数梳理

S32K1xx 微控制器的硬件設計指南
![[target tracking] | template update time context information (updatenet)](/img/53/0a8b2135fa4903f30e4573256c393a.png)
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"

【ROS进阶篇】第五讲 ROS中的TF坐标变换
随机推荐
Using swiper to make mobile phone rotation map
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(三)
SAP S/4HANA: 一条代码线,许多种选择
Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
"Qt+pcl Chapter 6" point cloud registration ICP Series 6
Redis秒杀demo
[leetcode] 16. The sum of the nearest three numbers
opencv学习笔记五--文件扫描+OCR文字识别
张驰课堂:六西格玛数据的几种类型与区别
Hidden rules of the workplace that must be understood before 30
What if you are always bullied because you are too honest in the workplace?
【ROS进阶篇】第五讲 ROS中的TF坐标变换
Qt+pcl Chapter 6 point cloud registration ICP Series 5
《QT+PCL第六章》点云配准icp系列3
TS reports an error don't use 'object' as a type The `object` type is currently hard to use
《QT+PCL第六章》点云配准icp系列5
STM32ADC模拟/数字转换详解
Tableapi & SQL and MySQL insert data of Flink