浏览我们的产品

If so you can download any of the below versions for testing. The product will function as normal except for an evaluation limitation. At the time of purchase we provide a license file via email that will allow the product to work in its full capacity. If you would also like an evaluation license to test without any restrictions for 30 days, please follow the directions provided here.


Product Docs Swagger Examples Blog Support Dashboard

安装

该软件包在 npmjs.com 可用,可通过执行以下命令使用 npm 安装:

npm install groupdocs-viewer-cloud

NPM Version NPM Downloads NPM-GroupDocsCloud


要求

依赖项

SDK 需要以下包:

PackageConstraint
axios1.8.4
form-data*
jsonwebtoken9.0.1
qs6.11.2

快速入门

获取 API 凭证

要使用 GroupDocs.Viewer Cloud,请在 GroupDocs.Cloud Dashboard 注册并获取 Client ID 和 Client Secret。

初始化 API

使用以下代码开始使用 GroupDocs.Viewer Cloud SDK for Node.js。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const viewApi = viewer_cloud.ViewApi.fromConfig(config);

请参阅 RunExamples.js 中的完整示例。

转换并下载文档

初始化后,使用此基本示例将本地文档渲染为 JPG,而不上传到云存储。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");
const fs = require("fs");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const viewApi = viewer_cloud.ViewApi.fromConfig(config);

(async () => {
    let format = "jpg";
    let filebuf = fs.readFileSync("./Resources/SampleFiles/sample.docx");
    let request = new viewer_cloud.ConvertAndDownloadRequest(format, filebuf);
    let response = await viewApi.convertAndDownload(request);
    console.log("ConvertAndDownload completed: " + response.length);
})();

请参阅 ConvertAndDownload.js 中的完整示例。

将文档渲染为响应式 HTML

此示例创建具有响应式布局的 HTML 视图。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const viewApi = viewer_cloud.ViewApi.fromConfig(config);

(async () => {
    let fileInfo = new viewer_cloud.FileInfo();
    fileInfo.filePath = "SampleFiles/sample.docx";
    let viewOptions = new viewer_cloud.ViewOptions();
    viewOptions.fileInfo = fileInfo;
    viewOptions.viewFormat = viewer_cloud.ViewOptions.ViewFormatEnum.HTML;
    viewOptions.renderOptions = new viewer_cloud.HtmlOptions();
    viewOptions.renderOptions.isResponsive = true;

    let request = new viewer_cloud.CreateViewRequest(viewOptions);
    let response = await viewApi.createView(request);
    console.log("HtmlViewerResponsiveLayout completed: " + response.pages.length);
})();

请参阅 HtmlViewerResponsiveLayout.js 中的完整示例。

渲染选定页面

此示例将文档的第 2 页和第 3 页渲染为 HTML。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const viewApi = viewer_cloud.ViewApi.fromConfig(config);

(async () => {
    let fileInfo = new viewer_cloud.FileInfo();
    fileInfo.filePath = "SampleFiles/sample.docx";
    let viewOptions = new viewer_cloud.ViewOptions();
    viewOptions.fileInfo = fileInfo;
    viewOptions.viewFormat = viewer_cloud.ViewOptions.ViewFormatEnum.HTML;
    viewOptions.renderOptions = new viewer_cloud.HtmlOptions();
    viewOptions.renderOptions.pagesToRender = [2, 3];

    let request = new viewer_cloud.CreateViewRequest(viewOptions);
    let response = await viewApi.createView(request);
    console.log("RenderSelectedPages completed: " + response.pages.length);
})();

请参阅 RenderSelectedPages.js 中的完整示例。

查看受密码保护的文档

此示例将受密码保护的 Word 文档渲染为 HTML。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const viewApi = viewer_cloud.ViewApi.fromConfig(config);

(async () => {
    let fileInfo = new viewer_cloud.FileInfo();
    fileInfo.filePath = "SampleFiles/password_protected.docx";
    fileInfo.password = "12345";
    let viewOptions = new viewer_cloud.ViewOptions();
    viewOptions.fileInfo = fileInfo;
    viewOptions.viewFormat = viewer_cloud.ViewOptions.ViewFormatEnum.HTML;

    let request = new viewer_cloud.CreateViewRequest(viewOptions);
    let response = await viewApi.createView(request);
    console.log("ViewProtectedDocument completed: " + response.pages.length);
})();

请参阅 ViewProtectedDocument.js 中的完整示例。

获取支持的查看格式

获取 API 可以渲染的文档格式。

"use strict";
const viewer_cloud = require("groupdocs-viewer-cloud");

const clientId = "YourClientId";
const clientSecret = "YourClientSecret";

const config = new viewer_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

const infoApi = viewer_cloud.InfoApi.fromConfig(config);

(async () => {
    let response = await infoApi.getSupportedFileFormats();
    console.log("Formats count: " + response.formats.length);
})();

请参阅 GetSupportedFormats.js 中的完整示例。

GitHub 上的示例

GroupDocs.Viewer Cloud Node.js Examples 仓库包含可直接运行的示例,涵盖:

CategoryExamples
Basic Usage转换并下载, HTML 查看器, 图像查看器, PDF 查看器, 文档信息, 附件, 支持的格式
Rendering Options选定页面, 连续页面, 水印, 笔记, 评论, 自定义字体
Loading Options受密码保护的文档, 编码
File Types压缩文件, CAD, 电子邮件, PDF, 电子表格, Visio, Word, Outlook 和项目文件

如何运行示例

  1. 克隆或下载示例仓库
  2. 编辑 Examples/RunExamples.js 并设置 clientId 和 clientSecret
  3. 进入 Examples 目录
  4. 运行 npm install
  5. 运行 npm update
  6. 执行 npm run-script start

更多详情请访问 Getting Started。


Product Docs Swagger Examples Blog Support Dashboard


Tags

Document Rendering API | Node.js Cloud API | GroupDocs.Viewer Cloud | REST API | HTML Rendering | PDF Conversion | Image Rendering | Document Viewing | Multi-Page Rendering | Document Streaming | CAD Rendering | E-Mail Message Rendering | Visio Rendering | MS Project Rendering | Outlook Data Rendering | Spreadsheet Rendering | Word Processing Rendering | Custom View Options | Responsive HTML | Attachment Rendering | Secure API Access | Cloud Storage Integration



 简体中文