Spire.PDF for .NET【页面设置】演示:从 PDF 中删除页面

PDF 文档可以包含多个页面,这些页面具有不同的文本内容、图像或其他对象。有时,用户可能需要删除某些页面,这些页面包含不正确绘制的对象或与文档主题无关的页面。本文将演示如何使用Spire.PDF for .NET以编程方式从现有 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.NET 包中包含的 DLL 文件作为引用添加到您的 .NET 项目中。 可以从此链接下载 DLL 文件,也可以通过NuGet安装。

复制代码
PM> Install-Package Spire.PDF
从 PDF 中删除页面
  • 创建一个PdfDocument对象。
  • **使用PdfDocument.LoadFromFile()**方法加载示例 PDF 文档。
  • 使用PdfDocument.Pages属性获取 PDF 文档中的页面。
  • **使用PdfPageCollection.RemoveAt(int index)**方法通过索引删除指定的页面。
  • **使用PdfDocument.SaveToFile()**方法将文档保存到另一个文件。

【C# 】

复制代码
using Spire.Pdf;

namespace RemovePage
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument document = new PdfDocument();

//Load a sample PDF document
document.LoadFromFile(@"E:\Files\input.pdf");

//Remove the second page
document.Pages.RemoveAt(1);

//Save the result document
document.SaveToFile("RemovePDFPage.pdf");
}
}
}

VB.NET

复制代码
Imports Spire.Pdf

Namespace RemovePage
Class Program
Private Shared Sub Main(ByVal args As String())

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

'Load a sample PDF document
document.LoadFromFile("E:\Files\input.pdf")

'Remove the second page
document.Pages.RemoveAt(1)

'Save the result document
document.SaveToFile("RemovePDFPage.pdf")
End Sub
End Class
End Namespace
相关推荐
山西茄子2 分钟前
GstAggregator的aggregate
开发语言·前端·javascript·gstreamer
Sailing6 分钟前
🚨别再滥用 useEffect 了!90% React Bug 的根源就在这
前端·javascript·面试
河马老师6 分钟前
写这需求快崩溃了,幸好我会装饰器模式
前端·javascript·面试
未来转换7 分钟前
Python-web开发之Flask框架入门
前端·python·flask
用户5757303346249 分钟前
🚀 拒绝“CSS 命名困难症”!手把手带你用 Tailwind CSS 搓一个“高颜值”登录页
前端
文静小土豆9 分钟前
标签和选择器(Label和 Selector)
linux·前端
学以智用12 分钟前
.NET Core 部署上线完整教程(Windows IIS / Linux / Docker)
后端·.net
wuhen_n16 分钟前
《Vue3+TS+Vite 高效编程与优化实践》专栏收尾
前端·javascript·vue.js
kevinten1020 分钟前
折腾三个月,我把摩旅路线和 AI 搞在一起了
前端
偷光20 分钟前
大模型核心技术概述:Token、Prompt、Tool与Agent的关系详解
前端·ai·prompt·ai编程