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

边栏推荐
- Automatic, intelligent and visual! Deeply convinced of the eight designs behind sslo scheme
- 近半年内连获5家“巨头”投资,这家智能驾驶“黑马”受资本追捧
- 大龄测试/开发程序员该何去何从?是否会被时代抛弃?
- 华为发布HCSP-Solution-5G Security人才认证,助力5G安全人才生态建设
- Connect the ABAP on premises system to the central inspection system for custom code migration
- Tensorflow team: we haven't been abandoned
- Trace the source of drugs and tamp the safety dike
- Detailed explanation of stm32adc analog / digital conversion
- 6.2 normalization 6.2.6 BC normal form (BCNF) 6.2.9 normalization summary
- 【php毕业设计】基于php+mysql+apache的教材管理系统设计与实现(毕业论文+程序源码)——教材管理系统
猜你喜欢
Nuxt. JS data prefetching
大龄测试/开发程序员该何去何从?是否会被时代抛弃?
How to adjust the color of the computer screen and how to change the color of the computer screen
周少剑,很少见
Lean Six Sigma project counseling: centralized counseling and point-to-point counseling
What time do you get off work?!!!
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
[video memory optimization] deep learning video memory optimization method
超视频时代,什么样的技术会成为底座?
华为发布HCSP-Solution-5G Security人才认证,助力5G安全人才生态建设
随机推荐
基于PHP的轻量企业销售管理系统
关于用 ABAP 代码手动触发 SAP CRM organization Model 自动决定的研究
Rhcsa fourth day operation
远程办公经验?来一场自问自答的介绍吧~ | 社区征文
How to adjust the color of the computer screen and how to change the color of the computer screen
[PHP graduation design] design and implementation of textbook management system based on php+mysql+apache (graduation thesis + program source code) -- textbook management system
C#/VB.NET 合并PDF文档
Stm32f411 SPI2 output error, pb15 has no pulse debugging record [finally, pb15 and pb14 were found to be short circuited]
Go语学习笔记 - gorm使用 - 表增删改查 | Web框架Gin(八)
ADS算力芯片的多模型架构研究
2023 spring recruitment Internship - personal interview process and face-to-face experience sharing
Microservice tracking SQL (support Gorm query tracking under isto control)
AVL 平衡二叉搜索树
picgo快捷键 绝了这人和我的想法 一模一样
Nuxt.js数据预取
大龄测试/开发程序员该何去何从?是否会被时代抛弃?
电脑屏幕变色了怎么调回来,电脑屏幕颜色怎么改
【OpenCV 例程200篇】216. 绘制多段线和多边形
July 1, 2022 Daily: Google's new research: Minerva, using language models to solve quantitative reasoning problems
[one day learning awk] function and user-defined function