Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render Excel Data to PDF using a REST API in Node.js
1. Render Excel Data to PDF using a REST API in Node.js
2. Render Excel Data to PDF with Advanced Options
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972";
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618";
global.myStorage = "";
const configuration = new groupdocs_viewer_cloud.Configuration(clientId, clientSecret);
configuration.apiBaseUrl = "https://api.groupdocs.cloud";
// initialize api
var fileApi = groupdocs_viewer_cloud.FileApi.fromConfig(configuration);
// create file download request
let request = new groupdocs_viewer_cloud.DownloadFileRequest("/viewer/sample_xlsx/sample.pdf", myStorage);
// download file
let response = await fileApi.downloadFile(request);
// save image file in working directory
fs.writeFile("C:\\Files\\sample.pdf", response, "binary", function (err) { });
console.log(response);
// api initialization
let viewApi = groupdocs_viewer_cloud.ViewApi.fromKeys(clientId, clientSecret);
// provide input file
let fileInfo = new groupdocs_viewer_cloud.FileInfo();
fileInfo.filePath = "sample.xlsx";
// define view options
let viewOptions = new groupdocs_viewer_cloud.ViewOptions();
viewOptions.fileInfo = fileInfo;
viewOptions.viewFormat = groupdocs_viewer_cloud.ViewOptions.ViewFormatEnum.PDF;
// create view request
let request = new groupdocs_viewer_cloud.CreateViewRequest(viewOptions);
// cretae view
let response = await viewApi.createView(request);
console.log("Document rendered: " + response.file.path);
// api initialization
let viewApi = groupdocs_viewer_cloud.ViewApi.fromKeys(clientId, clientSecret);
// provide input file path
let fileInfo = new groupdocs_viewer_cloud.FileInfo();
fileInfo.filePath = "sample.xlsx";
// define view options
let viewOptions = new groupdocs_viewer_cloud.ViewOptions();
viewOptions.fileInfo = fileInfo;
viewOptions.viewFormat = groupdocs_viewer_cloud.ViewOptions.ViewFormatEnum.PDF;
// define pdf render options
viewOptions.renderOptions = new groupdocs_viewer_cloud.PdfOptions();
// create spreadsheet options
viewOptions.renderOptions.spreadsheetOptions = new groupdocs_viewer_cloud.SpreadsheetOptions();
// hide text in adjacent columns
viewOptions.renderOptions.spreadsheetOptions.textOverflowMode = groupdocs_viewer_cloud.SpreadsheetOptions.TextOverflowModeEnum.HideText;
// show grid line
viewOptions.renderOptions.spreadsheetOptions.renderGridLines = true;
// show hidden cloumns
viewOptions.renderOptions.spreadsheetOptions.renderHiddenColumns = true;
// show hidden rows
viewOptions.renderOptions.spreadsheetOptions.renderHiddenRows = true;
// create view request
let request = new groupdocs_viewer_cloud.CreateViewRequest(viewOptions);
// create view
let response = await viewApi.createView(request);
console.log("Document rendered: " + response.file.path);
// construct FileApi
let fileApi = groupdocs_viewer_cloud.FileApi.fromConfig(configuration);
let resourcesFolder = 'C:\\Files\\sample.xlsx';
// read files one by one
fs.readFile(resourcesFolder, (err, fileStream) => {
// create upload file request
let request = new groupdocs_viewer_cloud.UploadFileRequest("sample.xlsx", fileStream, myStorage);
// upload file
fileApi.uploadFile(request);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment