@accusoft/document-processing-helper 中文文档教程

发布于 5年前 浏览 22 项目主页 更新于 3年前

document-processing-helper (BETA)

用于文档处理的简单 node.js 帮助程序,由 PrizmDoc Server 提供支持。 您可以将此助手与 PrizmDoc Cloud 或您自己的自托管 PrizmDoc 服务器一起使用。

如果您没有自己的 PrizmDoc Server 实例,最简单的入门方法是使用 PrizmDoc Cloud。 在 https://cloud.accusoft.com/ 注册免费试用帐户以获取 API 密钥。

需要节点 8 或更高版本。

Installation

npm install @accusoft/document-processing-helper

Example Usage

Converting a JPEG to PDF

const Helper = require('@accusoft/document-processing-helper');

async function main() {
  const documentProcessingHelper = new Helper({
    prizmDocServerBaseUrl: 'https://api.accusoft.com',
    apiKey: 'YOUR_API_KEY'
  });

  // Initialize a conversion
  const output = await documentProcessingHelper.convert({
      input: 'input.jpeg',
      outputFormat: 'pdf'
    });

  // Download the output and save the file
    await output[0].saveToFile('output.pdf');
}

main();

Converting a multipage PDF to PNG files (one PNG per page)

const Helper = require('@accusoft/document-processing-helper');

async function main() {
  const documentProcessingHelper = new Helper({
    prizmDocServerBaseUrl: 'https://api.accusoft.com',
    apiKey: 'YOUR_API_KEY'
  });

  // Initialize a conversion
  const output = await documentProcessingHelper.convert({
      input: 'input.pdf',
      outputFormat: 'png'
    });

  // Save each ouput PNG file
  for (let i = 0; i < output.length; i++) {
    await output[i].saveToFile('page-' + i + '.png');
  }
}

main();

API Reference

Class: Helper

Constructor

  • argumentsObject (object)
  • prizmDocServerBaseUrl (string) Required. Location of your PrizmDoc Server.
  • apiKey (string) Required for PrizmDoc Cloud. Your PrizmDoc Cloud API key.

convert(argumentsObject)

将文档从一种文件类型转换为另一种文件类型。

  • argumentsObject (object)

  • input (string, buffer, stream) 必需。 要转换的输入文件的文件路径、缓冲区或流

  • outputFormat(字符串)必需。 输出格式。 必须是以下值之一:

    • "pdf"
    • "docx" - Input must be a PDF.
    • "tiff"
    • "jpeg" - Produces multiple output files, one per page.
    • "png" - Produces multiple output files, one per page.
  • 返回:Output[] - Output 实例数组。

Class: Output

saveToFile(filepath)

将转换结果保存到文件中。

  • filepath (string) Required. Path, including filename, where the output should be saved.

document-processing-helper (BETA)

Simple node.js helper for document processing, powered by PrizmDoc Server. You can use this helper with either PrizmDoc Cloud or your own self-hosted PrizmDoc Server.

If you don't have your own PrizmDoc Server instance, the easiest way to get started is with PrizmDoc Cloud. Sign up for a free trial account to get an API key at https://cloud.accusoft.com/.

Requires node 8 or higher.

Installation

npm install @accusoft/document-processing-helper

Example Usage

Converting a JPEG to PDF

const Helper = require('@accusoft/document-processing-helper');

async function main() {
  const documentProcessingHelper = new Helper({
    prizmDocServerBaseUrl: 'https://api.accusoft.com',
    apiKey: 'YOUR_API_KEY'
  });

  // Initialize a conversion
  const output = await documentProcessingHelper.convert({
      input: 'input.jpeg',
      outputFormat: 'pdf'
    });

  // Download the output and save the file
    await output[0].saveToFile('output.pdf');
}

main();

Converting a multipage PDF to PNG files (one PNG per page)

const Helper = require('@accusoft/document-processing-helper');

async function main() {
  const documentProcessingHelper = new Helper({
    prizmDocServerBaseUrl: 'https://api.accusoft.com',
    apiKey: 'YOUR_API_KEY'
  });

  // Initialize a conversion
  const output = await documentProcessingHelper.convert({
      input: 'input.pdf',
      outputFormat: 'png'
    });

  // Save each ouput PNG file
  for (let i = 0; i < output.length; i++) {
    await output[i].saveToFile('page-' + i + '.png');
  }
}

main();

API Reference

Class: Helper

Constructor

  • argumentsObject (object)
  • prizmDocServerBaseUrl (string) Required. Location of your PrizmDoc Server.
  • apiKey (string) Required for PrizmDoc Cloud. Your PrizmDoc Cloud API key.

convert(argumentsObject)

Converts a document from one file type to another.

  • argumentsObject (object)

  • input (string, buffer, stream) Required. File path, buffer, or stream of the input file to convert

  • outputFormat (string) Required. Output format. Must be one of the following values:

    • "pdf"
    • "docx" - Input must be a PDF.
    • "tiff"
    • "jpeg" - Produces multiple output files, one per page.
    • "png" - Produces multiple output files, one per page.
  • Returns: Output[] - Array of Output instances.

Class: Output

saveToFile(filepath)

Saves the result of a conversion to a file.

  • filepath (string) Required. Path, including filename, where the output should be saved.
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文