当前位置:网站首页>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

边栏推荐
- "Qt+pcl Chapter 6" point cloud registration ICP Series 6
- 《QT+PCL第六章》点云配准icp系列6
- S32K1xx 微控制器的硬件设计指南
- Recommendation of data acquisition tools and detailed graphic process of data acquisition list
- Tableapi & SQL and Kafka message insertion in Flink
- Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
- [one day learning awk] function and user-defined function
- Basic use process of cmake
- Day 3 of rhcsa study
- 贝联珠贯加入龙蜥社区,共同促进碳中和
猜你喜欢
Phpcms background upload picture button cannot be clicked
S32K1xx 微控制器的硬件设计指南
Qt+pcl Chapter 6 point cloud registration ICP Series 2
微信小程序01-底部导航栏设置
【显存优化】深度学习显存优化方法
Intelligent operation and maintenance practice: banking business process and single transaction tracking
Zhang Chi's class: several types and differences of Six Sigma data
Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
微信小程序02-轮播图实现与图片点击跳转
微信网页订阅消息实现
随机推荐
Survey of intrusion detection systems:techniques, datasets and challenges
How to realize clock signal frequency division?
微信小程序01-底部导航栏设置
选择在长城证券上炒股开户可以吗?安全吗?
【云动向】6月上云新风向!云商店热榜揭晓
Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
Short Wei Lai grizzly, to "touch China" in the concept of stocks for a living?
Flink 系例 之 TableAPI & SQL 与 MYSQL 数据查询
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
Implementation of deploying redis sentry in k8s
Filter & (login interception)
MySQL审计插件介绍
What are the EN ISO 20957 certification standards for common fitness equipment
【天线】【3】CST一些快捷键
异常检测中的浅层模型与深度学习模型综述(A Unifying Review of Deep and Shallow Anomaly Detection)
STM32ADC模拟/数字转换详解
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
OpenSSL client programming: SSL session failure caused by an insignificant function
Opencv Learning Notes 6 -- image mosaic
[Cloudera][ImpalaJDBCDriver](500164)Error initialized or created transport for authentication