Created
August 6, 2021 12:34
-
-
Save groupdocs-cloud-gists/c9bd32896c0b072d797158479cf270df to your computer and use it in GitHub Desktop.
Render Excel Data to PDF using a REST API in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Render Excel Data to PDF using a REST API in Node.js | |
2. Render Excel Data to PDF with Advanced Options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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