在本主题中,您将学习如何使用 Node.js REST API 将 BMP 转换为 PDF。我们将遵循以下章节中详细清晰的步骤,使用 Node.js Low Code API 开发一个BMP 转 PDF 转换器。此应用程序可以与 Windows、Linux 或 macOS 环境中支持的任何 Node.js 应用程序集成,并且转换过程免费。
先决条件
- 创建帐户并获取 API 凭证 执行 BMP 到 PDF 的转换
- 下载 适用于 Node.js 的 Aspose.Imaging Cloud SDK 将 BMP 转换为 PDF
- 使用上述 SDK 设置 Node.js 项目以将 BMP 渲染为 PDF
使用 Node.js REST API 将 BMP 转换为 PDF 的步骤
- 设置 API 的客户端 ID 和客户端密钥以将 BMP 转换为 PDF
- 使用客户端凭据创建 ImagingAPI 类的实例以执行 BMP 到 PDF 的转换
- 指定源 BMP 和输出 PDF 文件名
- 读取源BMP文件并上传至云存储
- 使用输入文件流和输出 PDF 格式创建 ConvertImageRequest 实例
- 调用 图像转换 方法使用 Node.js REST API 将 BMP 转换为 PDF
- 将输出的 PDF 文件与返回的响应流一起保存在本地磁盘上
上述步骤使用 Node.js Low Code API 将文件类型从 BMP 转换为 PDF。我们将首先通过创建 ImagingAPI 类对象来初始化 SDK 的配置。然后,我们将使用 FileStream 加载源 BMP 文件,并实例化 ConvertImageRequest 类对象,该对象随后将使用 ConvertImage() 方法将其转换为 PDF。
Node.js Low Code API 中 BMP 到 PDF 转换的代码
此示例代码可帮助您使用 Node.js Cloud API 将 BMP 转换为 PDF。您只需借助 Aspose.Imaging REST API SDK 提供一个 BMP 文件,然后下载输出的 PDF 文件并保存到本地即可。您还可以通过在 ConvertImageRequest 对象实例化期间设置各种属性来进一步自定义转换过程,在本示例代码中,这些属性默认设置为 null。
In this tutorial, we have learned to transform BMP to PDF with Cloud API. If you are interested in performing BMP to JPEG conversion, refer to the article on how to Convert BMP to JPEG with Node.js REST API.