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

XLS TO PDF, Convertion not working completly

Hello,

I using the community license of syncfusion Xls.IO. I am in an Razor Application in .Net 6.0 hosted in a docker.

I am using latest nuget :

  • <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
  • <PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="20.3.0.56" />
  • <PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="20.3.0.56" />

I need to convert all worksheet of an Excel File identically to PDF but the convertion is not working for all my files ..Only part of the XLSX File is converted to PDF.


If i use your live demo (http://asp.syncfusion.com/demos/web/xlsio/exceltopdf.aspx) the problem is repoduced.


My code :

/// <summary>

        /// Converts the workbook to PDF.

        /// </summary>

        /// <param name="workbook">The workbook.</param>

        /// <param name="orientationMode">The orientation mode.</param>

        /// <param name="settings">The settings.</param>

        /// <returns></returns>

        private static PdfDocument ConvertWorkbookToPDF(this IWorkbook workbook, OrientationMode orientationMode, PdfSettings settings)

        {

            //Intialize the PdfDocument Class

            var pdfDoc = new PdfDocument

            {

                Compression = PdfCompressionLevel.None

            };


            // Configure Renderer

            XlsIORenderer renderer = new();


            // Allow chart rendering

            renderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png;

            renderer.ChartRenderingOptions.ScalingMode = ScalingMode.Best;


            //Intialize the ExcelToPdfConverterSettings class

            var _XlsIORendererSettings = new XlsIORendererSettings

            {

                EmbedFonts = true,

                AutoDetectComplexScript = true,

                ExportBookmarks = false,

                ExportDocumentProperties = true,

                ExportQualityImage = false,

                EnableFormFields = false,

                ThrowWhenExcelFileIsEmpty = true,

                IsConvertBlankPage = false,

                IsConvertBlankSheet = false,

                RenderBySheet = true,

                PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B,

                DisplayGridLines = GridLinesDisplayStyle.Auto,

                //Assign the output PdfDocument to the TemplateDocument property of ExcelToPdfConverterSettings

                TemplateDocument = pdfDoc

            };

            //Set the layout options of converter settings

            if (orientationMode == Application.Enums.OrientationMode.Portrait)

            {

                // Portrait

                _XlsIORendererSettings.TemplateDocument.PageSettings.Orientation = PdfPageOrientation.Portrait;

                _XlsIORendererSettings.TemplateDocument.PageSettings.Size = PdfPageSize.A4;

            }

            else

            {

                // Landscape

                _XlsIORendererSettings.TemplateDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;

                _XlsIORendererSettings.TemplateDocument.PageSettings.Size = PdfPageSize.A3;

            }

            _XlsIORendererSettings.LayoutOptions = LayoutOptions.FitSheetOnOnePage;

            _XlsIORendererSettings.TemplateDocument.PageSettings.Margins.All = 0.1f;

            pdfDoc = renderer.ConvertToPDF(workbook, _XlsIORendererSettings);

            return pdfDoc;

        }


Could you help me ?

Thank you.



Attachment: SampleExcelFile_f1b3d6c3.zip

3 Replies

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team November 16, 2022 10:28 AM

Only the range in Print Area is being converted to PDF because the input Excel document has Print Area configured. This is the behaviour of Microsoft Excel. Hence, we suggest you clear the print area in the input document and use that for conversion.



NO Nonobis November 17, 2022 04:21 PM

Thank you for your response, i will try your solution.



KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team November 18, 2022 07:05 AM

You're welcome, Nonobis. Please try the solution and contact us if you need any further assistance.


Loader.
Live Chat Icon For mobile
Up arrow icon