使用 Node.js REST API 从 PDF 文档中删除页面

本简短教程将指导您如何使用 Node.js REST API 从 PDF 文档中删除页面。您将了解如何使用基于 Node.js 的 Cloud SDK,无需任何第三方工具,即可使用 Node.js REST 接口删除 PDF 页面。如有需要,我们将讨论从 PDF 中删除多个页面的选项。

先决条件

使用 Node.js Low Code API 从 PDF 文档中删除页面的步骤

  1. 通过设置删除页面的客户端 ID 和密钥来实例化 PdfApi 类对象
  2. 将源 PDF 文件加载到内存流中以删除页面
  3. 将内存流中的文件上传至云存储
  4. 通过提供页码和上传的 PDF 文件名来调用 删除页面() 方法
  5. 使用 API 响应保存输出 PDF 文件

以下步骤介绍了如何使用 Node.js REST API 删除 PDF 中的页面。使用内存流将源 PDF 文件上传到云存储并为其命名。调用 DeletePage() 方法,提供上传的文件引用和要删除的目标页码(页码从 1 开始)。

使用 Node.js RESTful 服务消除 PDF 页面的代码

The above sample code demonstrates how to delete the pages in PDF with Node.js-based API. While uploading a PDF file, a name is assigned to it that is used by the DeletePage() method, and pages are deleted in the PDF file in the Cloud Storage. Once you complete deleting the single or multiple pages by iterating the process, you can download the updated file from the cloud storage and save it on the disk.

This article has taught us how to remove pages of a PDF with Node.js REST Interface. If you want to count words in a PDF file, refer to the following article: 使用 Node.js REST API 统计 PDF 文档中的字数.

 简体中文