We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Spreadsheet pdf orientation

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;

    }

}


4 Replies

SP Sangeetha Priya Murugan Syncfusion Team November 18, 2022 02:13 PM UTC

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



M M replied to Sangeetha Priya Murugan November 18, 2022 03:15 PM UTC

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



SP Sangeetha Priya Murugan Syncfusion Team November 21, 2022 02:00 PM UTC

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



SP Sangeetha Priya Murugan Syncfusion Team February 8, 2023 06:53 AM UTC

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


Loader.
Live Chat Icon For mobile
Up arrow icon