Hello,
I'm trying to have the exported pdf from the javascript spreadsheet library in the landscape orientation.
My beforeSave function looks like this:
beforeSave: function (args) {
if (args.saveType == 'Pdf') {
args.pdfLayoutSettings.fitSheetOnOnePage = true;
// possible solution something like this?
// args.pdfPageSettings.orientation = PdfPageOrientation.Landscape;
}
}
Hi Marcel,
Your requirement can be achieved by setting the orientation property as shown below in the server side save action.
Code Example:
[HttpPost] [Route("Save")] public IActionResult Save([FromForm] SaveSettings saveSettings) {
if (saveSettings.SaveType.ToString() == "Pdf") { saveSettings.SaveType = SaveType.Xlsx; ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; Stream fileStream = Workbook.Save<Stream>(saveSettings);
IWorkbook workbook = application.Workbooks.Open(fileStream);
saveSettings.SaveType = SaveType.Pdf;
//Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings();
//Set layout option as FitAllColumnsOnOnePage settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
//Initialize XlsIORenderer XlsIORenderer renderer = new XlsIORenderer();
int i, sheetCnt = workbook.Worksheets.Count; for (i = 0; i < sheetCnt; i++) { workbook.Worksheets[i].PageSetup.PrintGridlines = true; settings.DisplayGridLines = GridLinesDisplayStyle.Auto; } //Convert the Excel document to PDF with renderer settings PdfDocument document = renderer.ConvertToPDF(workbook, settings);
//Adds page settings document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 50;
//Saving the Excel to the MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream);
//Set the position as '0' stream.Position = 0;
//Download the PDF file in the browser FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "Output.pdf"; return fileStreamResult; } else { return Workbook.Save(saveSettings); } } |
Please find the sample link below.
Sample Link: https://stackblitz.com/edit/react-woka1m-minvcw?file=index.js
Service Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebAPI-PDF644225911
Note: Launch the service first and then open the stackblitz sample for import and export.
Could you please check the above details and get back to us if you need any further assistance on this.
Regards,
Sangeetha M
Hi Sangeetha M,
Thank you for your quick response!
I'm using the endpoint syncfusion is providing (https://ej2services.syncfusion.com/production/web-services/api/spreadsheet/save).
Is it possible to add parameters to the request so it will be rendered in landscape?
Best regards,
Marcel
Currently, we don’t have support to include an orientation setting for PDF export in a spreadsheet. But we have considered this as an improvement, and it will be available in any of our upcoming releases. Appreciate your patience until then. You can track the status of this improvement using the link below from our feedback portal.
Feedback Portal Link: https://www.syncfusion.com/feedback/39241/provide-support-to-add-the-orientation-settings-for-pdf-export
Hi Marcel,
We are glad to announce that our weekly patch release (20.4.49) is rolled out. And we have included the fix for the reported requirement in this release. So, kindly upgrade your scripts and assemblies’ versions to the latest to avail of these changes (20.4.49).
CSS Link: https://cdn.syncfusion.com/ej2/20.4.49/material.css
Script Link: https://cdn.syncfusion.com/ej2/20.4.49/dist/ej2.min.js
Package Link: https://www.nuget.org/packages/Syncfusion.EJ2.Spreadsheet.AspNet.Core
Sample Link: https://stackblitz.com/edit/1urgih?file=index.js
Feedback link: https://www.syncfusion.com/feedback/39241/provide-support-to-add-the-orientation-settings-for-pdf-export
Please let us know if you need further assistance on this.
Regards,
Sangeetha M