HTML JPG PDF XML DOCX
  Product Family
PDF

在 Node.js SDK 中将 BMP 转换为 PDF

使用 Aspose.PDF Cloud Node.js SDK 将 BMP 文档导出为多种格式,包括 PDF

Get Started

如何使用 Node.js SDK 将 BMP 转换为 PDF

为了将 BMP 转换为 PDF,我们将使用 Aspose.PDF Cloud Node.js SDK 该云端 SDK 帮助 Node.js 程序员使用 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。打开 NPM 包管理器,搜索 Aspose.PDF Cloud, 并安装。您也可以使用以下命令从包管理器控制台进行安装。

包管理器控制台命令


     
    npm install asposepdfcloud --save
     
     

通过 Node.js 将 BMP 转换为 PDF 的步骤

Aspose.PDF Cloud Node.js 开发人员可以轻松地用几行代码加载并转换 BMP 文件为 PDF。

  1. 从 JSON 文件中加载您的应用程序密钥和密钥,或以其他方式设置凭据
  2. 创建一个对象以连接到云 API
  3. 上传您的文档文件
  4. 使用 putImageInStorageToPdf 执行转换
  5. 如有需要,下载结果
 

此示例代码显示 BMP 到 PDF 云 Node.js SDK 转换


    const fs = require("fs");
    const credentials = require("./credentials.json");
    const { PdfApi } = require("asposepdfcloud");
    const { ImageTemplatesRequest } = require("asposepdfcloud/src/models/imageTemplatesRequest");
    const { ImageTemplate } = require("asposepdfcloud/src/models/imageTemplate");
    const { ImageSrcType } = require("asposepdfcloud/src/models/imageSrcType");

    // Load your Application Secret and Key from the JSON file or set credentials in another way
    async function convertBMPtoPDF() {
        const localImageFileName = "C:\\Samples\\sample.bmp";
        const storageImageFileName = "sample.bmp";
        const pdfApi = new PdfApi(credentials.id, credentials.key);
        try {
            let fileData = await fs.readFile(localImageFileName);
            let uploadResult = await pdfApi.uploadFile(storageImageFileName, fileData);
            console.log(uploadResult.response.text);
        }
        catch (error) {
            console.error(error.response.text);
        }
        let imageTemplateList = [];
        let imageTemplate = new ImageTemplate();
        imageTemplate.imagePath = storageImageFileName;
        imageTemplate.imageSrcType = ImageSrcType.Common;
        imageTemplateList.push(imageTemplate);

        let imageTemplatesRequest = new ImageTemplatesRequest()
        imageTemplatesRequest.IsOCR = false;
        imageTemplatesRequest.imagesList = imageTemplateList;

        try {
            let convertResult = await pdfApi.putImageInStorageToPdf("sample-bmp-to-pdf.pdf", imageTemplatesRequest);
            console.log(convertResult.response.text);
            const buffer = await pdfApi.downloadFile(STORAGE_FILENAME);
        } catch (error) {
            console.error(error.response.text);
        }
    }
 
  • 其他支持的转换

    您还可以将 MD 转换为许多其他文件格式,包括以下列出的几种。

    BMP 转 PDF (位图图像)
    CGM 转 PDF (Microsoft Word 二进制格式)
    EMF 转 PDF (Office 2007+ Word 文档)
    EPUB 转 PDF (增强型图元文件格式)
    GIF 转 PDF (图形交换格式)
    HTML 转 PDF (超文本标记语言)
    JPEG 转 PDF (联合图像专家组)
    LATEX 转 PDF (LaTeX 输出文本)
    PCL 转 PDF (打印机命令语言)
    MD 转 PDF (Markdown)
    PDF 转 BMP (位图图像)
    PDF 转 EPUB (电子书格式)
    PDF 转 GIF (图形交换格式)
    PDF 转 HTML (超文本标记语言)
    PDF 转 JPEG (联合图像专家组)
    PDF 转 PDF/A (便携式文档格式)
    PDF 转 PNG (便携式网络图形)
    PDF 转 PPTX (微软PowerPoint)
    PDF 转 SVG (可缩放矢量图形)
    PDF 转 TEX (计算机图形系统)
    PDF 转 TIFF (标记图像文件格式)
    PDF 转 WORD (微软Word二进制格式)
    PDF 转 XLSX (微软Excel开放XML格式电子表格文件)
    PDF 转 XPS (XML纸张规格)
    PNG 转 PDF (便携式网络图形)
    PS 转 PDF (PostScript)
    SVG 转 PDF (可缩放矢量图形)
    TEXT 转 PDF (文本文件)
    TIFF 转 PDF (标记图像文件格式)
    XPS 转 PDF (XML纸张规格)