We’re using node.js groupdocs-viewer-cloud 24.8.0.
Here’s the code:
import { readFile, writeFile } from "fs/promises";
import viewer, {
Configuration,
DownloadFileRequest,
FileInfo,
RenderOptions,
SpreadsheetOptions,
UploadFileRequest,
ViewOptions
} from "groupdocs-viewer-cloud";
import { uuid } from "@voyfai/uuid";
const excelBuffer = await readFile("test.xlsx");
const clientId = process.env.GROUPDOCS_CLIENT_ID;
const clientSecret = process.env.GROUPDOCS_CLIENT_SECRET;
if (!clientId || !clientSecret) {
throw new Error("Please set GROUPDOCS_CLIENT_ID and GROUPDOCS_CLIENT_SECRET environment variables");
}
// Set output HTML options, one file per page
const fileId = uuid();
const config = new Configuration(clientId, clientSecret);
const viewApi = viewer.ViewApi.fromConfig(config);
const fileApi = viewer.FileApi.fromConfig(config);
const uploadRequest: UploadFileRequest = {
path: `${fileId}.xlsx`,
file: excelBuffer,
storageName: "" // Use default storage
};
const uploadResult = await fileApi.uploadFile(uploadRequest);
const view = await viewApi.createView({
viewOptions: new ViewOptions({
fileInfo: new FileInfo({
filePath: uploadResult.uploaded[0]
}),
viewFormat: ViewOptions.ViewFormatEnum.PDF,
outputPath: fileId,
renderOptions: new RenderOptions({
spreadsheetOptions: new SpreadsheetOptions({
/**
* Allows to enable worksheets pagination. By default one worksheet is rendered into one page.
*/
paginateSheets: false,
/**
* The number of rows rendered into one page when PaginateSheets is enabled. Default value is 50.
*/
// countRowsPerPage: 10,
/**
* The columns count to include into each page when splitting worksheet into pages.
*/
// countColumnsPerPage: 50,
/**
* Indicates whether to render grid lines
*/
renderGridLines: true,
/**
* By default empty rows are skipped. Enable this option in case you want to render empty rows.
*/
renderEmptyRows: true,
/**
* By default empty columns are skipped. Enable this option in case you want to render empty columns.
*/
renderEmptyColumns: true,
/**
* Enables rendering of hidden rows.
*/
renderHiddenRows: true,
/**
* Enables rendering of hidden columns.
*/
renderHiddenColumns: true,
/**
* Enables headings rendering.
*/
renderHeadings: true,
/**
* Enables rendering worksheet(s) sections which is defined as print area. Renders each print area in a worksheet as a separate page.
*/
renderPrintAreaOnly: false,
/**
* The text overflow mode for rendering spreadsheet documents into HTML
*/
textOverflowMode: SpreadsheetOptions.TextOverflowModeEnum.AutoFitColumn
})
})
})
});
const downloadRequest: DownloadFileRequest = {
path: view.file.path,
storageName: "", // Use default storage
versionId: "" // Use latest version
};
const buffer = await fileApi.downloadFile(downloadRequest);
await writeFile(`${fileId}.pdf`, buffer);
here’s the original:
Screenshot 2024-11-15 at 16.49.47.png (35.8 KB)
here’s the result as seen in the pdf we download. Chinese characters are replaced with squares.
Screenshot 2024-11-15 at 16.49.57.png (299.3 KB)
Unlike in the @groupdocs/groupdocs.viewer, there’s no option to set the encoding or charset when dowloading a file.
Is there a way to solve this problem, or is it somewhere on your server?