当前位置:网站首页>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
边栏推荐
- [video memory optimization] deep learning video memory optimization method
- 2023届春招实习-个人面试过程和面经分享
- Deep operator overloading (2)
- Go语学习笔记 - gorm使用 - 表增删改查 | Web框架Gin(八)
- Tanabata confession introduction: teach you to use your own profession to say love words, the success rate is 100%, I can only help you here ~ (programmer Series)
- Win11如何設置用戶權限?Win11設置用戶權限的方法
- 揭秘慕思“智商税”:狂砸40亿搞营销,发明专利仅7项
- VIM from dislike to dependence (22) -- automatic completion
- Go language learning notes - Gorm use - table addition, deletion, modification and query | web framework gin (VIII)
- ATSs: automatically select samples to eliminate the difference between anchor based and anchor free object detection methods
猜你喜欢

STM32F1与STM32CubeIDE编程实例-PWM驱动蜂鸣器生产旋律
![[video memory optimization] deep learning video memory optimization method](/img/87/795429126aef284d55d2217f393ecb.png)
[video memory optimization] deep learning video memory optimization method

Some abilities can't be learned from work. Look at this article, more than 90% of peers

自動、智能、可視!深信服SSLO方案背後的八大設計

vscode 查找 替换 一个文件夹下所有文件的数据

Go语学习笔记 - gorm使用 - 表增删改查 | Web框架Gin(八)

HR interview: the most common interview questions and technical answers

The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's eldest disciple

STM32ADC模拟/数字转换详解

超视频时代,什么样的技术会成为底座?
随机推荐
One revolution, two forces, three links: the "carbon reduction" roadmap behind the industrial energy efficiency improvement action plan
Pocket Network为Moonbeam和Moonriver RPC层提供支持
Overview | slam of laser and vision fusion
How to adjust the size of computer photos to what you want
跨平台应用开发进阶(二十四) :uni-app实现文件下载并保存
Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
周少剑,很少见
How to adjust the color of the computer screen and how to change the color of the computer screen
【OpenCV 例程200篇】216. 绘制多段线和多边形
Sales management system of lightweight enterprises based on PHP
【LeetCode】43. String multiplication
搜索框和按钮缩放时会有缝隙的bug
Day 3 of rhcsa study
基于PHP的轻量企业销售管理系统
综述 | 激光与视觉融合SLAM
[target tracking] |stark
使用腾讯云搭建图床服务
Go language learning notes - Gorm use - table addition, deletion, modification and query | web framework gin (VIII)
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
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速