Spire.PDF for .NET【文档操作】演示:将PDF拆分为多个PDF文件

本文介绍了Spire.PDFfor.NET,一个用于.NET程序的PDF控件,演示了如何在C#和VB.NET中创建PDF、编辑现有文档,以及如何将PDF按页面或页面范围拆分。该库由E-iceblue开发,支持国产环境和文档格式。
摘要由CSDN通过智能技术生成

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

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

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

安装适用于 .NET 的 Spire.PDF

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

PM> Install-Package Spire.PDF
使用 C#、VB.NET 将 PDF 拆分为一页 PDF

Spire.PDF提供Split()方法将多页PDF文档分割成多个单页文件。以下是详细步骤。

  • 创建一个PdfDcoument对象。
  • 使用PdfDocument.LoadFromFile()方法加载 PDF 文档。
  • 使用PdfDocument.Split(string destFilePattern, int startNumber)方法将文档拆分为一页 PDF 。

[C#]

using System;
using Spire.Pdf;

namespace SplitPDFIntoIndividualPages
{
class Program
{
static void Main(string[] args)
{
//Specify the input file path
String inputFile = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf";

//Specify the output directory
String outputDirectory = "C:\\Users\\Administrator\\Desktop\\Output\\";

//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a PDF file
doc.LoadFromFile(inputFile);

//Split the PDF to one-page PDFs
doc.Split(outputDirectory + "output-{0}.pdf", 1);
}
}
}

【VB.NET】

Imports System
Imports Spire.Pdf

Namespace SplitPDFIntoIndividualPages
Class Program
Shared Sub Main(ByVal args() As String)
'Specify the path of the input file
Dim inputFile As String = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf"

'Specify the output directory
Dim outputDirectory As String = "C:\\Users\\Administrator\\Desktop\\Output\\"

'Create a PdfDocument object
Dim doc As PdfDocument = New PdfDocument()

'Load a PDF file
doc.LoadFromFile(inputFile)

'Split the PDF to one-page PDFs
doc.Split(outputDirectory + "output-{0}.pdf", 1)
End Sub
End Class
End Namespace

C#/VB.NET:将 PDF 拆分为单独的 PDF

在 C#、VB.NET 中按页面范围拆分 PDF

没有提供按页面范围拆分 PDF 文档的直接方法。为此,我们创建两个或多个新的 PDF 文档,并将源文档中的页面或页面范围导入到其中。以下是详细步骤。

  • 初始化PdfDocument对象时加载源 PDF 文件。
  • 创建两个额外的PdfDocument对象。
  • 使用PdfDocument.InsertPage()方法将第一页从源文件导入到第一个文档。
  • 使用PdfDocument.InsertPageRange()方法将剩余页面从源文件导入到第二个文档。
  • 使用PdfDocument.SaveToFile()方法将两个文档保存为单独的 PDF 文件。

[C#]

using Spire.Pdf;
using System;

namespace SplitPdfByPageRanges
{
class Program
{
static void Main(string[] args)
{
//Specify the input file path
String inputFile = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf";

//Specify the output directory
String outputDirectory = "C:\\Users\\Administrator\\Desktop\\Output\\";

//Load the source PDF file while initialing the PdfDocument object
PdfDocument sourceDoc = new PdfDocument(inputFile);

//Create two additional PdfDocument objects
PdfDocument newDoc_1 = new PdfDocument();
PdfDocument newDoc_2 = new PdfDocument();

//Insert the first page of source file to the first document
newDoc_1.InsertPage(sourceDoc, 0);

//Insert the rest pages of source file to the second document
newDoc_2.InsertPageRange(sourceDoc, 1, sourceDoc.Pages.Count - 1);

//Save the two documents as PDF files
newDoc_1.SaveToFile(outputDirectory + "output-1.pdf");
newDoc_2.SaveToFile(outputDirectory + "output-2.pdf");
}
}
}

【VB.NET】

Imports Spire.Pdf
Imports System

Namespace SplitPdfByPageRanges
Class Program
Shared Sub Main(ByVal args() As String)
'Specify the input file path
Dim inputFile As String = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf"

'Specify the output directory
Dim outputDirectory As String = "C:\\Users\\Administrator\\Desktop\\Output\\"

'Load the source PDF file while initialing the PdfDocument object
Dim sourceDoc As PdfDocument = New PdfDocument(inputFile)

'Create two additional PdfDocument objects
Dim NewDoc_1 As PdfDocument = New PdfDocument()
Dim NewDoc_2 As PdfDocument = New PdfDocument()

'Insert the first page of source file to the first document
NewDoc_1.InsertPage(sourceDoc, 0)

'Insert the rest pages of source file to the second document
NewDoc_2.InsertPageRange(sourceDoc, 1, sourceDoc.Pages.Count - 1)

'Save the two documents as PDF files
NewDoc_1.SaveToFile(outputDirectory + "output-1.pdf")
NewDoc_2.SaveToFile(outputDirectory + "output-2.pdf")
End Sub
End Class
End Namespace

C#/VB.NET:将 PDF 拆分为单独的 PDF

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

  • 27
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Free Spire.PDF for .NET 是一个用于.NET平台的免费PDF处理库。它提供了一套强大的功能,可以用于创建、编辑和处理PDF文档。无论是在Windows应用程序还是Web应用程序中,Free Spire.PDF for .NET 都能帮助我们轻松实现对PDF文件操作。 首先,Free Spire.PDF for .NET 支持创建和编辑PDF文档。我们可以使用库中提供的API来创建新的PDF文档,添加页面、文本、图像和表格等内容,并设置页面的布局和样式。同时,我们还可以使用库中的功能来编辑现有的PDF文档,例如添加、提取和删除页面,修改文本、图像和表格等。 其次,Free Spire.PDF for .NET 还提供了丰富的PDF处理功能,可以帮助我们完成一些特定的操作。例如,我们可以使用库中的API来提取、合并和拆分PDF文档,将多个PDF文件合并为一个,或者将一个PDF文件拆分多个部分。此外,库中还提供了加密和解密PDF文档的功能,可以帮助我们保护敏感的PDF文件内容。 除了基本的PDF处理功能之外,Free Spire.PDF for .NET 还支持高级功能,如转换PDF文档到其他格式,例如HTML、Word、Excel和图像等。我们可以使用库中的API将PDF文件转换为其他格式的文件,便于我们在不同的应用程序中使用。 总之,Free Spire.PDF for .NET 是一个功能强大、易于使用且免费的PDF处理库。它提供了一系列实用的API,可以帮助我们创建、编辑和处理PDF文档,完成各种PDF操作。无论是在个人项目中还是商业应用中,Free Spire.PDF for .NET 都是一个不错的选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值