Skip to content

Node.js module to communicate with GroupDocs.Viewer REST API. View or render Word, Excel, PowerPoint, CAD, Visio, PDF, OpenDocument, email & image formats.

License

Notifications You must be signed in to change notification settings

groupdocs-viewer-cloud/groupdocs-viewer-cloud-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GroupDocs.Viewer Cloud SDK for Node.js

This repository contains GroupDocs.Viewer Cloud SDK for Node.js source code. This SDK allows you to work with GroupDocs.Viewer Cloud REST APIs in your Node.js applications, enabling you to render documents in HTML, image, or PDF formats, with the flexibility to render the whole document or a custom range of pages.

Installation

A package groupdocs-viewer-cloud is available at npmjs.com. You can install it with:

npm install groupdocs-viewer-cloud

Getting Started

Below is an example demonstrating how to preview a document using ConvertAndDownload with GroupDocs.Viewer Cloud SDK for Node.js:

const GroupDocs = require('groupdocs-viewer-cloud');
const fs = require('fs');

// Get your appSid and appKey at https://dashboard.groupdocs.cloud
const appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
const appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

const configuration = new GroupDocs.Configuration(appSid, appKey);
const viewApi = new GroupDocs.ViewApi(configuration);

const format = "jpg";
const fileStream = fs.createReadStream("myfile.docx");
const request = new GroupDocs.ConvertAndDownloadRequest(format, fileStream);

viewApi.convertAndDownload(request)
    .then((result) => {
        fs.writeFileSync("myfile.jpg", result);
        console.log("Document converted and downloaded as JPG.");
    })
    .catch((error) => {
        console.log("Error: " + error.message);
    });

Below is an example demonstrating how to upload a document, render it, and download the result using GroupDocs.Viewer Cloud SDK for Node.js:

const GroupDocs = require('groupdocs-viewer-cloud');
const fs = require('fs');

const appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
const appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

const configuration = new GroupDocs.Configuration(appSid, appKey);

// Upload a file to cloud storage
const fileApi = new GroupDocs.FileApi(configuration);
const uploadRequest = new GroupDocs.UploadFileRequest("myfile.docx", fs.createReadStream("myfile.docx"));
fileApi.uploadFile(uploadRequest)
    .then(() => {
        // Render it to HTML
        const viewApi = new GroupDocs.ViewApi(configuration);
        const viewOptions = new GroupDocs.ViewOptions({
            fileInfo: { filePath: "myfile.docx" },
            viewFormat: "HTML",
            outputPath: "myfile.html"
        });
        const createViewRequest = new GroupDocs.CreateViewRequest(viewOptions);
        return viewApi.createView(createViewRequest);
    })
    .then(() => {
        // Download the result
        const downloadRequest = new GroupDocs.DownloadFileRequest("myfile.html");
        return fileApi.downloadFile(downloadRequest);
    })
    .then((result) => {
        fs.writeFileSync("myfile.html", result);
        console.log("File rendered and downloaded successfully.");
    })
    .catch((error) => {
        console.log("Error: " + error.message);
    });

Or compile and run the same written in TypeScript:

import { Configuration, FileApi, ViewApi, UploadFileRequest, ViewOptions, CreateViewRequest, DownloadFileRequest, ConvertAndDownloadRequest } from "groupdocs-viewer-cloud";
import * as fs from "fs";

const appSid: string = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
const appKey: string = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

const configuration = new Configuration(appSid, appKey);

// Convert and download
const viewApi = new ViewApi(configuration);
const format = "jpg";
const fileStream = fs.createReadStream("myfile.docx");
const request = new ConvertAndDownloadRequest(format, fileStream);

viewApi.convertAndDownload(request)
    .then((result) => {
        fs.writeFileSync("myfile.jpg", result);
        console.log("Document converted and downloaded as JPG.");
    })
    .catch((error) => {
        console.log("Error: " + error.message);
    });

// Upload, render, and download
const fileApi = new FileApi(configuration);
const uploadRequest = new UploadFileRequest("myfile.docx", fs.createReadStream("myfile.docx"));
fileApi.uploadFile(uploadRequest)
    .then(() => {
        const viewOptions = new ViewOptions({
            fileInfo: { filePath: "myfile.docx" },
            viewFormat: "HTML",
            outputPath: "myfile.html"
        });
        const createViewRequest = new CreateViewRequest(viewOptions);
        return viewApi.createView(createViewRequest);
    })
    .then(() => {
        const downloadRequest = new DownloadFileRequest("myfile.html");
        return fileApi.downloadFile(downloadRequest);
    })
    .then((result) => {
        fs.writeFileSync("myfile.html", result);
        console.log("File rendered and downloaded successfully.");
    })
    .catch((error) => {
        console.log("Error: " + error.message);
    });

Licensing

GroupDocs.Viewer Cloud Node.js SDK is licensed under MIT License.

Resources

Contact Us

Your feedback is very important to us. Please feel free to contact us using

About

Node.js module to communicate with GroupDocs.Viewer REST API. View or render Word, Excel, PowerPoint, CAD, Visio, PDF, OpenDocument, email & image formats.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5