How To Save Angular Spreadsheet As Single-Sheet PDF In Landscape Mode?
This knowledge base article explains how to save Angular Spreadsheet as a PDF file in a single sheet with landscape mode. This can be achieved by setting the fitSheetOnOnePage property to true and the orientation property to Landscape in the pdfLayoutSettings. These settings are applied by verifying that the saveTypeis Pdf in the beforeSave event, which is triggered before the save action in the Spreadsheet component.
[app.component.html]
<div class="control-section">
<ejs-spreadsheet #default [openUrl]="openUrl" [saveUrl]="saveUrl" (created)="created()" (beforeSave)="beforeSave($event)">
<e-sheets>
<e-sheet name="Car Sales Report">
<e-ranges>
<e-range [dataSource]="data"></e-range>
</e-ranges>
<e-columns>
<e-column [width]=180></e-column>
<e-column [width]=130></e-column>
<e-column [width]=130></e-column>
<e-column [width]=180></e-column>
<e-column [width]=130></e-column>
<e-column [width]=120></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>
</div>
[app.component.ts]
import { Component, ViewEncapsulation, Inject, ViewChild } from '@angular/core';
import { getDefaultData } from './data';
import { SpreadsheetComponent, SpreadsheetModule } from '@syncfusion/ej2-angular-spreadsheet';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
encapsulation: ViewEncapsulation.None,
standalone: true,
imports: [ SpreadsheetModule, ]
})
export class AppComponent {
constructor() {
}
@ViewChild('default')
public spreadsheetObj: SpreadsheetComponent;
public data: Object[] = getDefaultData();
public openUrl = 'https://services.syncfusion.com/angular/production/api/spreadsheet/open';
public saveUrl = 'https://services.syncfusion.com/angular/production/api/spreadsheet/save';
created() {
this.spreadsheetObj.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1');
}
beforeSave(args) {
if (args.saveType === "Pdf") {
args.pdfLayoutSettings = { fitSheetOnOnePage: true, orientation: 'Landscape' }
}
}
}
Sample link: https://stackblitz.com/edit/angular-f5lii7-adnh3h?file=src%2Fapp.component.ts
Output:
Conclusion
I hope you enjoyed learning about how to save Angular Spreadsheet as single-sheet PDF in landscape mode.
You can refer to our Angular Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Spreadsheet example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!