当前位置:网站首页>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
边栏推荐
- Pnas: brain and behavior changes of social anxiety patients with empathic embarrassment
- 摩根大通期货开户安全吗?摩根大通期货公司开户方法是什么?
- 雷神科技冲刺北交所,拟募集资金5.4亿元
- S32K1xx 微控制器的硬件设计指南
- 关于用 ABAP 代码手动触发 SAP CRM organization Model 自动决定的研究
- SAP S/4HANA: 一条代码线,许多种选择
- Qt+pcl Chapter 6 point cloud registration ICP Series 5
- Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
- 《性能之巅第2版》阅读笔记(五)--file-system监测
- How to realize clock signal frequency division?
猜你喜欢

A unifying review of deep and shallow anomaly detection

Short Wei Lai grizzly, to "touch China" in the concept of stocks for a living?
![[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"
![opencv学习笔记六--图像特征[harris+SIFT]+特征匹配](/img/50/5c8adacea78e470c255070c8621ddd.png)
opencv学习笔记六--图像特征[harris+SIFT]+特征匹配

STM32F411 SPI2输出错误,PB15无脉冲调试记录【最后发现PB15与PB14短路】

STM32ADC模拟/数字转换详解

雷神科技冲刺北交所,拟募集资金5.4亿元

opencv学习笔记五--文件扫描+OCR文字识别

Opencv learning note 4 -- bank card number recognition

Opencv learning notes 5 -- document scanning +ocr character recognition
随机推荐
Hardware design guide for s32k1xx microcontroller
智能运维实战:银行业务流程及单笔交易追踪
phpcms后台上传图片按钮无法点击
Phpcms background upload picture button cannot be clicked
Logical analysis of automatic decision of SAP CRM organization model
Photoshop plug-in HDR (II) - script development PS plug-in
Research on manually triggering automatic decision of SAP CRM organization model with ABAP code
Summary of empty string judgment in the project
Flink 系例 之 TableAPI & SQL 与 Kafka 消息插入
Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
Basic use process of cmake
SAP s/4hana: one code line, many choices
Beilianzhuguan joined the dragon lizard community to jointly promote carbon neutralization
使用 csv 导入的方式在 SAP S/4HANA 里创建 employee 数据
Flink 系例 之 TableAPI & SQL 与 MYSQL 插入数据
微服务追踪SQL(支持Isto管控下的gorm查询追踪)
Opencv learning note 4 -- bank card number recognition
skywalking 6.4 分布式链路跟踪 使用笔记
Connect the ABAP on premises system to the central inspection system for custom code migration
Photoshop插件-HDR(二)-脚本开发-PS插件