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

边栏推荐
- SQL常用的四个排序函数梳理
- [STM32 learning] w25qxx automatic judgment capacity detection based on STM32 USB storage device
- 重回榜首的大众,ID依然乏力
- Guide de conception matérielle du microcontrôleur s32k1xx
- 【天线】【3】CST一些快捷键
- Research on manually triggering automatic decision of SAP CRM organization model with ABAP code
- Connect the ABAP on premises system to the central inspection system for custom code migration
- go-zero实战demo(一)
- 《QT+PCL第六章》点云配准icp系列4
- 【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(三)
猜你喜欢
opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
【ROS进阶篇】第五讲 ROS中的TF坐标变换
张驰咨询:锂电池导入六西格玛咨询降低电池容量衰减
雷神科技冲刺北交所,拟募集资金5.4亿元
Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
Junda technology - wechat cloud monitoring scheme for multiple precision air conditioners
[advanced ROS] lesson 5 TF coordinate transformation in ROS
Survey of intrusion detection systems:techniques, datasets and challenges
STM32F411 SPI2输出错误,PB15无脉冲调试记录【最后发现PB15与PB14短路】
STM32F4-TFT-SPI时序逻辑分析仪调试记录
随机推荐
STM32F411 SPI2输出错误,PB15无脉冲调试记录【最后发现PB15与PB14短路】
张驰咨询:家电企业用六西格玛项目减少客户非合理退货案例
说明 | 华为云云商店「商品推荐榜」
Tableapi & SQL and Kafka message insertion in Flink
Qt+pcl Chapter 6 point cloud registration ICP Series 5
《QT+PCL第九章》点云重建系列2
《QT+PCL第六章》点云配准icp系列5
The last picture is seamlessly connected with the first picture in the swiper rotation picture
采集数据工具推荐,以及采集数据列表详细图解流程
微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南
Sort out the four commonly used sorting functions in SQL
Day 3 of rhcsa study
Recommendation of data acquisition tools and detailed graphic process of data acquisition list
TS reports an error don't use 'object' as a type The `object` type is currently hard to use
Tiantou village, Guankou Town, Xiamen special agricultural products Tiantou Village special agricultural products ant new village 7.1 answer
JS中箭头函数和普通函数的区别
Zhang Chi Consulting: household appliance enterprises use Six Sigma projects to reduce customers' unreasonable return cases
Microservice tracking SQL (support Gorm query tracking under isto control)
厦门灌口镇田头村特色农产品 甜头村特色农产品蚂蚁新村7.1答案
Implementation of deploying redis sentry in k8s