当前位置:网站首页>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
边栏推荐
- [one day learning awk] function and user-defined function
- SAP CRM organization Model(组织架构模型)自动决定的逻辑分析
- opencv学习笔记五--文件扫描+OCR文字识别
- [300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (III)
- Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
- 微信小程序02-轮播图实现与图片点击跳转
- go-zero实战demo(一)
- How to realize clock signal frequency division?
- The solution to turn the newly created XML file into a common file in idea
- Raytheon technology rushes to the Beijing stock exchange and plans to raise 540million yuan
猜你喜欢

MySQL 服务正在启动 MySQL 服务无法启动解决途径

Wechat applet 03 - text is displayed from left to right, and the block elements in the line are centered

Opencv learning notes 5 -- document scanning +ocr character recognition

Introduction to MySQL audit plug-in

【目标跟踪】|模板更新 时间上下文信息(UpdateNet)《Learning the Model Update for Siamese Trackers》
![[target tracking] |stark](/img/e2/83e9d97cfb8c49cfb8d912cfe2f858.png)
[target tracking] |stark

It's settled! 2022 Hainan secondary cost engineer examination time is determined! The registration channel has been opened!

精益六西格玛项目辅导咨询:集中辅导和点对点辅导两种方式

Microservice tracking SQL (support Gorm query tracking under isto control)

Phpcms background upload picture button cannot be clicked
随机推荐
张驰咨询:锂电池导入六西格玛咨询降低电池容量衰减
[Cloudera][ImpalaJDBCDriver](500164)Error initialized or created transport for authentication
[cloud trend] new wind direction in June! Cloud store hot list announced
Zhang Chi's class: several types and differences of Six Sigma data
What if you are always bullied because you are too honest in the workplace?
go-zero实战demo(一)
如何实现时钟信号分频?
ThinkPHP进阶
Summary of empty string judgment in the project
S32K1xx 微控制器的硬件設計指南
Redis high availability principle
Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
Zhang Chi Consulting: household appliance enterprises use Six Sigma projects to reduce customers' unreasonable return cases
A unifying review of deep and shallow anomaly detection
常见健身器材EN ISO 20957认证标准有哪些
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(三)
Wechat applet 02 - Implementation of rotation map and picture click jump
重回榜首的大众,ID依然乏力
精益六西格玛项目辅导咨询:集中辅导和点对点辅导两种方式
Microservice tracking SQL (support Gorm query tracking under isto control)