当前位置:网站首页>C#/VB. Net merge PDF document
C#/VB. Net merge PDF document
2022-07-01 15:57:00 【InfoQ】
Will be multiple PDF Merge into one PDF file
- Get the paths of the documents to be merged and store them in a string array .
- call PdfDocument.MergeFiles() Method to merge documents .
- use PdfDocumentBase.Save() Method is saved as a PDF file
using System;
using Spire.Pdf;
namespace MergePDFs
{
class Program
{
static void Main(string[] args)
{
// Get the path of the document to be merged
String[] files = new String[] {
"Sample.pdf",
"Sample1.pdf",
"Samplex.pdf"
// Merge documents
PdfDocumentBase doc = PdfDocument.MergeFiles(files);
// Save the results to PDF file
doc.Save("MergeDocuments.pdf", FileFormat.PDF);
}
}
}
Imports System
Imports Spire.Pdf
Namespace MergePDFs
Class Program
Private Shared Sub Main(ByVal args() As String)
' Get the path of the document to be merged
Dim files() As String = New String() {" Sample.pdf", "Sample-1.pdf", "Samplex.pdf"}
' Merge documents
Dim doc As PdfDocumentBase = PdfDocument.MergeFiles(files)
' Save the results to PDF file
doc.Save("output.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace

Will be different PDF The specified pages of are merged into one PDF file
- Get the path of the source document and store them in the string array .
- Create a PdfDocument Array , And load each source document into a separate PdfDocument object .
- Use PdfDocument.InsertPage() Methods and PdfDocument.InsertPageRange() Method to insert the specified page of the source document into the new document .
- use PdfDocument.SaveToFile() Method to save the new document as PDF.
using System;
using Spire.Pdf;
namespace MergeSelectedPages
{
class Program
{
static void Main(string[] args)
{
// Get the path of the document to be merged
String[] files = new String[] {
"Sample1.pdf",
"Sample.pdf",
"Sample2.pdf"};
// Create a PdfDocument Array
PdfDocument[] docs = new PdfDocument[files.Length];
// Cycle through documents
for (int i = 0; i < files.Length; i++)
{
// Load the specified document
docs[i] = new PdfDocument(files[i]);
}
// Create a PdfDocument Object to generate a new PDF file
PdfDocument doc = new PdfDocument();
// Insert the specified pages in different documents into the new document
doc.InsertPage(docs[0], 0);
doc.InsertPageRange(docs[1], 0, 2);
doc.InsertPage(docs[2], 1);
// Save the document as PDF file
doc.SaveToFile("output.pdf");
}
}
}
Imports System
Imports Spire.Pdf
Namespace MergeSelectedPages
Class Program
Private Shared Sub Main(ByVal args() As String)
' Get the path of the document to be merged
Dim files() As String = New String() {"Sample1.pdf", "Sample.pdf", "Sample2.pdf"}
' Create a PdfDocument Array
Dim docs() As PdfDocument = New PdfDocument((files.Length) - 1) {}
' Cycle through documents
Dim i As Integer = 0
Do While (i < files.Length)
' Load the specified document
docs(i) = New PdfDocument(files(i))
i = (i + 1)
Loop
' Create a PdfDocument Object to generate a new PDF file
Dim doc As PdfDocument = New PdfDocument
' Insert the specified pages in different documents into the new document
doc.InsertPage(docs(0), 0)
doc.InsertPageRange(docs(1), 0, 2)
doc.InsertPage(docs(2), 1)
' Save the document as PDF file
doc.SaveToFile("output.pdf")
End Sub
End Class
End Namespace

边栏推荐
- 近半年内连获5家“巨头”投资,这家智能驾驶“黑马”受资本追捧
- Share the daily work and welfare of DJI (Shenzhen headquarters) in Dajiang
- 一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图...
- Is JPMorgan futures safe to open an account? What is the account opening method of JPMorgan futures company?
- Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
- vscode 查找 替换 一个文件夹下所有文件的数据
- 【LeetCode】43. String multiplication
- Stm32f411 SPI2 output error, pb15 has no pulse debugging record [finally, pb15 and pb14 were found to be short circuited]
- Comment win11 définit - il les permissions de l'utilisateur? Win11 comment définir les permissions de l'utilisateur
- Trace the source of drugs and tamp the safety dike
猜你喜欢
自动、智能、可视!深信服SSLO方案背后的八大设计
近半年内连获5家“巨头”投资,这家智能驾驶“黑马”受资本追捧
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (III)
Go语学习笔记 - gorm使用 - 表增删改查 | Web框架Gin(八)
【显存优化】深度学习显存优化方法
[PHP graduation design] design and implementation of textbook management system based on php+mysql+apache (graduation thesis + program source code) -- textbook management system
HR interview: the most common interview questions and technical answers
u本位合约和币本位合约有区别,u本位合约会爆仓吗
Go language learning notes - Gorm use - table addition, deletion, modification and query | web framework gin (VIII)
One revolution, two forces, three links: the "carbon reduction" roadmap behind the industrial energy efficiency improvement action plan
随机推荐
七夕表白攻略:教你用自己的专业说情话,成功率100%,我只能帮你们到这里了啊~(程序员系列)
MySQL高级篇4
Introduction to RT thread env tool (learning notes)
马来西亚《星报》:在WTO MC12 孙宇晨仍在坚持数字经济梦想
Pico, can we save consumer VR?
HR面试:最常见的面试问题和技巧性答复
基于PHP的轻量企业销售管理系统
RT-Thread Env 工具介绍(学习笔记)
Description | Huawei cloud store "commodity recommendation list"
Day 3 of rhcsa study
开机时小键盘灯不亮的解决方案
TensorFlow團隊:我們沒被拋弃
Some abilities can't be learned from work. Look at this article, more than 90% of peers
[one day learning awk] function and user-defined function
【OpenCV 例程200篇】216. 绘制多段线和多边形
Win11如何設置用戶權限?Win11設置用戶權限的方法
跨平台应用开发进阶(二十四) :uni-app实现文件下载并保存
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
Crypto Daily:孙宇晨在MC12上倡议用数字化技术解决全球问题
[stm32-usb-msc problem help] stm32f411ceu6 (Weact) +w25q64+usb-msc flash uses SPI2 to read out only 520kb