@accusoft/prizmdoc-rest-client 中文文档教程

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

prizmdoc-rest-client (BETA)

(BETA) HTTP 客户端旨在简化与 PrizmDoc Server 的交互。 具体来说:

  1. Automatically handles affinity concerns
  2. Provides a way to easily poll for process completion

Installation

npm install @accusoft/prizmdoc-rest-client

Example Usage

这是一个演示将 JPEG 转换为 PDF 的示例:

const PrizmDocRestClient = require('@accusoft/prizmdoc-rest-client');
const fs = require('fs');

async function main() {
  // Construct an instance of the PrizmDocRestClient.
  const prizmdocServer = new PrizmDocRestClient({
    baseUrl: 'https://api.accusoft.com',
    headers: {
      'Acs-Api-Key': 'YOUR_API_KEY'
    }
  });

  // Create an affinity session for our processing work.
  //
  // You should use an affinity session anytime you have a group
  // of HTTP requests that go together as part of a processing
  // chain. The session ensures that all HTTP requests will
  // automatically use the same affinity (be routed to the same
  // PrizmDoc Server machine in the cluster).
  const session = prizmdocServer.createAffinitySession();

  let res;

  // Create a new work file for the input document
  res = await session.post('/PCCIS/V1/WorkFile', {
    body: fs.readFileSync('input.jpg')
  });

  const inputWorkFile = await res.json();

  // Start a conversion process using the input work file
  res = await session.post('/v2/contentConverters', {
    body: JSON.stringify({
      input: {
        sources: [
          {
            fileId: inputWorkFile.fileId
          }
        ],
        dest: {
          format: 'pdf'
        }
      }
    })
  });

  let process = await res.json();

  // Wait for the process to finish
  process = await session.getFinalProcessStatus(`/v2/contentConverters/${process.processId}`);

  // Did the process error?
  if (process.state !== 'complete') {
    throw new Error(`The process failed to complete: ${JSON.stringify(process, null, 2)}`);
  }

  // Download the output work file and save it to disk.
  res = await session.get(`/PCCIS/V1/WorkFile/${process.output.results[0].fileId}`);
  res.body.pipe(fs.createWriteStream('output.pdf'));
}

main();

prizmdoc-rest-client (BETA)

(BETA) HTTP client designed to simplify interactions with PrizmDoc Server. Specifically:

  1. Automatically handles affinity concerns
  2. Provides a way to easily poll for process completion

Installation

npm install @accusoft/prizmdoc-rest-client

Example Usage

Here's an example demonstrating converting a JPEG to PDF:

const PrizmDocRestClient = require('@accusoft/prizmdoc-rest-client');
const fs = require('fs');

async function main() {
  // Construct an instance of the PrizmDocRestClient.
  const prizmdocServer = new PrizmDocRestClient({
    baseUrl: 'https://api.accusoft.com',
    headers: {
      'Acs-Api-Key': 'YOUR_API_KEY'
    }
  });

  // Create an affinity session for our processing work.
  //
  // You should use an affinity session anytime you have a group
  // of HTTP requests that go together as part of a processing
  // chain. The session ensures that all HTTP requests will
  // automatically use the same affinity (be routed to the same
  // PrizmDoc Server machine in the cluster).
  const session = prizmdocServer.createAffinitySession();

  let res;

  // Create a new work file for the input document
  res = await session.post('/PCCIS/V1/WorkFile', {
    body: fs.readFileSync('input.jpg')
  });

  const inputWorkFile = await res.json();

  // Start a conversion process using the input work file
  res = await session.post('/v2/contentConverters', {
    body: JSON.stringify({
      input: {
        sources: [
          {
            fileId: inputWorkFile.fileId
          }
        ],
        dest: {
          format: 'pdf'
        }
      }
    })
  });

  let process = await res.json();

  // Wait for the process to finish
  process = await session.getFinalProcessStatus(`/v2/contentConverters/${process.processId}`);

  // Did the process error?
  if (process.state !== 'complete') {
    throw new Error(`The process failed to complete: ${JSON.stringify(process, null, 2)}`);
  }

  // Download the output work file and save it to disk.
  res = await session.get(`/PCCIS/V1/WorkFile/${process.output.results[0].fileId}`);
  res.body.pipe(fs.createWriteStream('output.pdf'));
}

main();
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文