Category / Section
How to set the printing to fit the page in Spreadsheet?
1 min read
This Knowledge Base explains how to set the printing to fit the page in JavaScript Spreadsheet. You can export the PDF file that get fitted into single page by setting pdfLayoutSettings.fitSheetOnOnePage as true in beforeSave event args. Using the below code, you can achieve this requirement
[HTML]
<div id="spreadsheet"></div>
[TS]
//Initialize Spreadsheet component let spreadsheet: Spreadsheet = new Spreadsheet({ sheets: [ { name: 'Car Sales Report', ranges: [{ dataSource: (dataSource as any).defaultData }], columns: [ { width: 180 }, { width: 130 }, { width: 130 }, { width: 180 }, { width: 130 }, { width: 120 }, { width: 130 }, ], }, ], created: (): void => { //Applies cell and number formatting to specified range of the active sheet spreadsheet.cellFormat( { fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:G1' ); spreadsheet.numberFormat('$#,##0.00', 'F2:F31'); }, beforeSave(args) { args.pdfLayoutSettings.fitSheetOnOnePage = true; // to export pdf in single page } }); //Render initialized Spreadsheet component spreadsheet.appendTo('#spreadsheet');
Sample Link: https://stackblitz.com/edit/yf5mla?file=index.ts
Output:
Documentation:
https://ej2.syncfusion.com/documentation/spreadsheet/open-save/