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
相关推荐
开开心心就好1 小时前
定时结束进程的小工具,到点还能关机
linux·运维·服务器·智能手机·pdf·电脑·word
夕水2 小时前
我把颜色选择器拆成了 15 个插件,最后长成了 22 个包
前端·javascript·typescript
大今野2 小时前
2026 专转本计算机|移动互联网关键技术:SOA、Web2.0 与 HTML5 考点全解(附例题)
前端·html·html5·专转本
JudithHuang2 小时前
Vue3 与后端联调:代理、Mock 与接口约定
前端·vue
Swot2 小时前
工具转换 vs LLM 转换:以 Markdown 转 AsciiDoc 为例
前端
uuware3 小时前
Lupine.js 的 Native 5 端实现:一套代码覆盖 iOS、Android、macOS、Windows 和 Web
前端·typescript
lisw053 小时前
前端:概念、历史、内容、挑战与展望!
前端
充值内卷4 小时前
从 WAML 到 PDF 阅读器:PentPDF 开发过程
pdf
ZHOUPUYU4 小时前
PHP 现代工程实践:从语言特性到高性能 Web 应用构建
android·前端·php