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

边栏推荐
- ADS算力芯片的多模型架构研究
- 将ABAP On-Premises系统连接到中央检查系统以进行自定义代码迁移
- STM32ADC模拟/数字转换详解
- Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
- MySQL高级篇4
- u本位合约和币本位合约有区别,u本位合约会爆仓吗
- 求求你们,别再刷 Star 了!这跟“爱国”没关系!
- #夏日挑战赛# HarmonyOS canvas实现时钟
- SAP S/4HANA: 一条代码线,许多种选择
- Seate中用了shardingjdbc 就不能用全局事务了吗?
猜你喜欢
Photoshop plug-in HDR (II) - script development PS plug-in
她就是那个「别人家的HR」|ONES 人物
How to adjust the color of the computer screen and how to change the color of the computer screen
[open source data] open source data set for cross modal (MRI, Meg, eye movement) human spatial memory research based on virtual reality scenes
Comment win11 définit - il les permissions de l'utilisateur? Win11 comment définir les permissions de l'utilisateur
AVL 平衡二叉搜索树
[PHP graduation design] design and implementation of textbook management system based on php+mysql+apache (graduation thesis + program source code) -- textbook management system
[stm32-usb-msc problem help] stm32f411ceu6 (Weact) +w25q64+usb-msc flash uses SPI2 to read out only 520kb
HR面试:最常见的面试问题和技巧性答复
[IDM] IDM downloader installation
随机推荐
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (III)
laravel的模型删除后动作
Detailed explanation of stm32adc analog / digital conversion
Create employee data in SAP s/4hana by importing CSV
二叉树的前序,中序,后续(非递归版本)
MySQL advanced 4
马来西亚《星报》:在WTO MC12 孙宇晨仍在坚持数字经济梦想
HR面试:最常见的面试问题和技巧性答复
STM32F1与STM32CubeIDE编程实例-PWM驱动蜂鸣器生产旋律
Samsung took the lead in putting 3nm chips into production, and Shanghai's fresh master students can settle directly. Nankai has established a chip science center. Today, more big news is here
表格存储中tablestore 目前支持mysql哪些函数呢?
What time do you get off work?!!!
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
【显存优化】深度学习显存优化方法
Advanced cross platform application development (24): uni app realizes file download and saving
你TM到底几点下班?!!!
ABAP-调用Restful API
DO280管理应用部署--pod调度控制
[200 opencv routines] 216 Draw polylines and polygons
[stm32-usb-msc problem help] stm32f411ceu6 (Weact) +w25q64+usb-msc flash uses SPI2 to read out only 520kb