当前位置:网站首页>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
边栏推荐
- 微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南
- opencv学习笔记四--银行卡号识别
- SAP S/4HANA: 一条代码线,许多种选择
- [Cloudera][ImpalaJDBCDriver](500164)Error initialized or created transport for authentication
- Reading notes of top performance version 2 (V) -- file system monitoring
- What are the test items of juicer ul982
- Is JPMorgan futures safe to open an account? What is the account opening method of JPMorgan futures company?
- 《QT+PCL第六章》点云配准icp系列2
- MySQL 服务正在启动 MySQL 服务无法启动解决途径
- MySQL审计插件介绍
猜你喜欢

Survey of intrusion detection systems:techniques, datasets and challenges
k8s部署redis哨兵的实现

An intrusion detection model

点云重建方法汇总一(PCL-CGAL)

微服务追踪SQL(支持Isto管控下的gorm查询追踪)

《QT+PCL第六章》点云配准icp系列2

入侵检测模型(An Intrusion-Detection Model)

opencv学习笔记六--图像拼接

Introduction to MySQL audit plug-in
![[leetcode] 16. The sum of the nearest three numbers](/img/60/6a68333d6e543c601e6ed586b830d0.png)
[leetcode] 16. The sum of the nearest three numbers
随机推荐
Phpcms background upload picture button cannot be clicked
Returning to the top of the list, the ID is still weak
《QT+PCL第九章》点云重建系列2
STM32ADC模拟/数字转换详解
[one day learning awk] conditions and cycles
Stm32f411 SPI2 output error, pb15 has no pulse debugging record [finally, pb15 and pb14 were found to be short circuited]
Junda technology - wechat cloud monitoring scheme for multiple precision air conditioners
[antenna] [3] some shortcut keys of CST
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
swiper 轮播图,最后一张图与第一张图无缝衔接
Sort out the four commonly used sorting functions in SQL
【STM32-USB-MSC问题求助】STM32F411CEU6 (WeAct)+w25q64+USB-MSC Flash用SPI2 读出容量只有520KB
MySQL高级篇4
What are the EN ISO 20957 certification standards for common fitness equipment
go-zero实战demo(一)
Microservice tracking SQL (support Gorm query tracking under isto control)
Implementation of wechat web page subscription message
Stm32f4-tft-spi timing logic analyzer commissioning record
vim 从嫌弃到依赖(22)——自动补全
Tableapi & SQL and Kafka message insertion in Flink