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 小时前
Java类型推断完全指南:从var到菱形运算符,掌握使用限制与最佳实践
java·前端·ai编程
To_OC3 小时前
踩了个 TS 的坑之后,我终于把 type 和 interface 掰明白了
前端·react.js·typescript
GreenTea3 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调
前端·后端·算法
浮生望3 小时前
前端API工程化:用 Mock 数据与 Axios 配置实现独立于后端的并行开发
前端
万少3 小时前
给 DeepSeek Harness 装个"应用商店":一条命令,595 个插件随你逛
前端·javascript·后端
波波0074 小时前
C# 15 重磅新特性: 带标签 break 与 continue:重新定义嵌套循环控制流
服务器·前端·c#
Brown.alexis4 小时前
es6知识点1-自备使用
前端·ecmascript·es6
小爬的老粉丝5 小时前
JavaScript 纯前端预览 WPS:先识别容器,再路由解析器
前端·javascript·wps
计算机魔术师6 小时前
新兴多智能体系统的模式与问题
前端
用户059540174467 小时前
AI Agent 上下文污染踩坑实录:用 pytest + Redis 揪出 3 类记忆串号 bug,排查 6 小时
前端·css