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
相关推荐
Ticnix1 小时前
ECharts初始化、销毁、resize 适配组件封装(含完整封装代码)
前端·echarts
纯爱掌门人1 小时前
终焉轮回里,藏着 AI 与人类的答案
前端·人工智能·aigc
twl1 小时前
OpenClaw 深度技术解析
前端
崔庆才丨静觅1 小时前
比官方便宜一半以上!Grok API 申请及使用
前端
星光不问赶路人2 小时前
vue3使用jsx语法详解
前端·vue.js
天蓝色的鱼鱼2 小时前
shadcn/ui,给你一个真正可控的UI组件库
前端
布列瑟农的星空2 小时前
前端都能看懂的Rust入门教程(三)——控制流语句
前端·后端·rust
Mr Xu_2 小时前
Vue 3 中计算属性的最佳实践:提升可读性、可维护性与性能
前端·javascript
jerrywus2 小时前
我写了个 Claude Code Skill,再也不用手动切图传 COS 了
前端·agent·claude
玖月晴空2 小时前
探索关于Spec 和Skills 的一些实战运用-Kiro篇
前端·aigc·代码规范