Spire.PDF for .NET【文档操作】演示:合并 PDF 文档

2024-04-16 08:52

本文主要是介绍Spire.PDF for .NET【文档操作】演示:合并 PDF 文档,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

需要合并 PDF 的原因有很多。例如,合并 PDF 文件允许您打印单个文件,而不是为打印机排队多个文档,组合相关文件通过减少要搜索和组织的文件数量来简化管理和存储多个文档的过程。在本文中,您将学习如何使用Spire.PDF for .NET将多个 PDF 文档合并为一个 PDF 文档,以及如何使用C# 和 VB.NET将不同 PDF 文档中的选定页面合并为一个 PDF 。

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.PDF for.net下载   Spire.PDF for java下载

安装适用于 .NET 的 Spire.PDF

首先,您需要将 Spire.PDF for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。 DLL 文件可以从此链接下载或通过NuGet安装。

PM> Install-Package Spire.PDF
将多个 PDF 合并为一个 PDF

Spire.PDF for .NET 提供PdfDocument.MergeFiles()方法将多个 PDF 文档合并为单个文档。详细步骤如下。

  • 获取要合并的文档的路径并将其存储在字符串数组中。
  • 调用PdfDocument.MergeFiles()方法来合并这些文件。
  • 使用PdfDocumentBase.Save()方法将结果保存到 PDF 文档。

C#

using System;
using Spire.Pdf;namespace MergePDFs
{
class Program
{
static void Main(string[] args)
{
//Get the paths of the documents to be merged
String[] files = new String[] {
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf",
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf",
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"};//Merge these documents and return an object of PdfDocumentBase
PdfDocumentBase doc = PdfDocument.MergeFiles(files);//Save the result to a PDF file
doc.Save("output.pdf", FileFormat.PDF);
}
}
}

VB.NET

Imports System
Imports Spire.PdfNamespace MergePDFs
Class Program
Shared Sub Main(ByVal args() As String)
'Get the paths of the documents to be merged
Dim files() As String = New String() {"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"}'Merge these documents and return an object of PdfDocumentBase
Dim doc As PdfDocumentBase = PdfDocument.MergeFiles(files)'Save the result to a PDF file
doc.Save("output.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace

C#/VB.NET:合并 PDF 文档

将不同 PDF 的选定页面合并为一个 PDF

Spire.PDF for .NET 提供PdfDocument.InsertPage()方法和PdfDocument.InsertPageRange()方法,用于将页面或页面范围从一个 PDF 文档导入到另一个 PDF 文档。以下是将不同 PDF 文档中的选定页面合并为一个新 PDF 文档的步骤。

  • 获取源文档的路径并将其存储在字符串数组中。
  • 创建PdfDocument数组,并将每个源文档加载到单独的PdfDocument对象中。
  • 创建另一个PdfDocument对象来生成新文档。
  • 使用PdfDocument.InsertPage()方法和PdfDocument.InsertPageRange()方法将源文档的选定页面或页面范围插入到新文档中。
  • 使用PdfDocument.SaveToFile()方法将新文档保存为 PDF 文件。

C#

using System;
using Spire.Pdf;namespace MergeSelectedPages
{
class Program
{
static void Main(string[] args)
{
//Get the paths of the documents to be merged
String[] files = new String[] {
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf",
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf",
"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"};//Create an array of PdfDocument
PdfDocument[] docs = new PdfDocument[files.Length];//Loop through the documents
for (int i = 0; i < files.Length; i++)
{
//Load a specific document
docs[i] = new PdfDocument(files[i]);
}//Create a PdfDocument object for generating a new PDF document
PdfDocument doc = new PdfDocument();//Insert the selected pages from different documents to the new document
doc.InsertPage(docs[0], 0);
doc.InsertPageRange(docs[1], 1,3);
doc.InsertPage(docs[2], 0);//Save the document to a PDF file
doc.SaveToFile("output.pdf");
}
}
}

VB.NET 

Imports System
Imports Spire.PdfNamespace MergeSelectedPagesClass ProgramShared  Sub Main(ByVal args() As String)'Get the paths of the documents to be mergedDim files() As String =  New String() {"C:\\Users\\Administrator\\Desktop\\PDFs\\sample-1.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-2.pdf","C:\\Users\\Administrator\\Desktop\\PDFs\\sample-3.pdf"}'Create an array of PdfDocumentDim docs() As PdfDocument =  New PdfDocument(files.Length) {} 'Loop through the documentsDim i As IntegerFor  i = 0 To  files.Length- 1  Step  i + 1'Load a specific documentdocs(i) = New PdfDocument(files(i))Next'Create a PdfDocument object for generating a new PDF documentDim doc As PdfDocument =  New PdfDocument() 'Insert the selected pages from different documents to the new documentdoc.InsertPage(docs(0), 0)doc.InsertPageRange(docs(1), 1,3)doc.InsertPage(docs(2), 0)'Save the document to a PDF filedoc.SaveToFile("output.pdf")End SubEnd Class
End Namespace

C#/VB.NET:合并 PDF 文档

以上便是如何合并 PDF文件,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~

这篇关于Spire.PDF for .NET【文档操作】演示:合并 PDF 文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/908337

相关文章

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

day-51 合并零之间的节点

思路 直接遍历链表即可,遇到val=0跳过,val非零则加在一起,最后返回即可 解题过程 返回链表可以有头结点,方便插入,返回head.next Code /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}*

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get

2、PF-Net点云补全

2、PF-Net 点云补全 PF-Net论文链接:PF-Net PF-Net (Point Fractal Network for 3D Point Cloud Completion)是一种专门为三维点云补全设计的深度学习模型。点云补全实际上和图片补全是一个逻辑,都是采用GAN模型的思想来进行补全,在图片补全中,将部分像素点删除并且标记,然后卷积特征提取预测、判别器判别,来训练模型,生成的像

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟)

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟) 题目描述 给定一个链表,链表中的每个节点代表一个整数。链表中的整数由 0 分隔开,表示不同的区间。链表的开始和结束节点的值都为 0。任务是将每两个相邻的 0 之间的所有节点合并成一个节点,新节点的值为原区间内所有节点值的和。合并后,需要移除所有的 0,并返回修改后的链表头节点。 思路分析 初始化:创建一个虚拟头节点