When converted excel to pdf - top portion with image and textboxes is missing in pdf

Hi,
I converted Excel to PDF using Syncfusion.XlsIORenderer(installed packages: syncfusion.xlsiorenderer.net.core(20.2.0.46) and syncfusion.xlsio.net.core(20.2.0.46)). 
But the top portion is missing in PDF which is present in Excel. The top portion contains a picture on top of the merged cells. There are two textboxes over the picture at the left and right end. The text boxes contain text in white color.
The top portion is missing in all worksheets.
Please note that we cannot update the excel template since it is working fine in other applications.


Image_7564_1691489489466

Code flow:
Read the Excel file template.
Open the Excel file and update its cell values and text box values.
Save Excel to local => the top portion with image and text boxes is present.
Convert Excel to pdf and verify pdf => the top portion with image and text boxes is missing.

But it worked in the following approaches:
1) I  tried to convert Excel to PDF using Microsoft.Interop.Excel then, the top portion was present.
The text boxes are blurred in the image since it contains private information.
Image_7690_1691490130434
2) I  saved the Excel to PDF locally. Then also, the top portion was present.
The below image shows the Excel.
Image_7248_1691490877129

3) We have a .NET Framework project which converts the same Excel to pdf using 
Syncfusion.ExcelToPdfConverter (20.2.0.46) also works fine.



1) Code used to convert Excel to PDF using Syncfusion.XlsIORenderer (saved memory stream to pdf - top portion is missing):

 private async Task<string> ConvertToPDF(IWorkbook destinationWorkbook, IApplication application, ExcelEngine excelEngine)

        {

            string directory = "PdfDocuments";

            string pdfFileName = $"{Guid.NewGuid()}_{DateTime.Now.Ticks}.pdf";

            Stream pdfStream = new FileStream(pdfFileName, FileMode.Create, FileAccess.ReadWrite);

            destinationWorkbook.ActiveSheetIndex = 0;

            destinationWorkbook.ActiveSheet.ActivePane = 0;

            destinationWorkbook.Version = ExcelVersion.Excel2016;

            using (MemoryStream memoryStreamMergedExcel = new())

            {

             memoryStreamMergedExcel.Position = 0;

            destinationWorkbook.SaveAs(memoryStreamMergedExcel);    

            // Important: set the MemoryStream position to zero

            memoryStreamMergedExcel.Position = 0;

                XlsIORenderer renderer = new();

                PdfDocument pdfDoc = new();      

                XlsIORendererSettings settings = new()

                {

                    TemplateDocument = pdfDoc,

                    DisplayGridLines = GridLinesDisplayStyle.Invisible,

                    AutoDetectComplexScript = true,

                    EmbedFonts = true,

                    ExportDocumentProperties = true,

                    RenderBySheet = true,

                    LayoutOptions = LayoutOptions.FitSheetOnOnePage,

                    ExportQualityImage = true,

                    IsConvertBlankPage = false,

                    IsConvertBlankSheet = false

                };

                pdfStream.Position = 0;

                pdfDoc = renderer.ConvertToPDF(memoryStreamMergedExcel, settings);

                pdfStream.Position = 0;

                pdfDoc.Save(pdfStream);

                pdfStream.Position = 0;

                //save the pdf file to azure blob storage

                await _azureUploadService.UploadFileStream(directory, pdfFileName, pdfStream, "container");

                pdfDoc.Close(true);

                destinationWorkbook.Close();

               memoryStreamMergedExcel.Dispose();

                pdfStream.Dispose();

                File.Delete(pdfFileName);

            }

            excelEngine.Dispose();

            return directory + pdfFileName;

        }

2) Code used to convert Excel to PDF using Syncfusion.XlsIORenderer (saved the workbook to pdf - top portion is missing):

private async Task<string> ConvertToPDF(IWorkbook destinationWorkbook, IApplication application, ExcelEngine excelEngine)
        {
            string directory = "TestDirectory";
            string pdfFileName = $"{Guid.NewGuid()}_{DateTime.Now.Ticks}.pdf";
            Stream pdfStream = new FileStream(pdfFileName, FileMode.Create, FileAccess.ReadWrite);

            destinationWorkbook.ActiveSheetIndex = 0;
            destinationWorkbook.Version = ExcelVersion.Excel2016;

            using (MemoryStream memoryStreamMergedExcel = new())
            {
                memoryStreamMergedExcel.Position = 0;
                destinationWorkbook.SaveAs(memoryStreamMergedExcel);
                destinationWorkbook.Close();

                IWorkbook workbook;

                // Important: set the MemoryStream position to zero
                memoryStreamMergedExcel.Position = 0;
                workbook = application.Workbooks.Open(memoryStreamMergedExcel);

                XlsIORenderer renderer = new();
                PdfDocument pdfDoc = new();

                XlsIORendererSettings settings = new()
                {
                    TemplateDocument = pdfDoc,
                    DisplayGridLines = GridLinesDisplayStyle.Invisible,
                };
                pdfDoc = renderer.ConvertToPDF(workbook, settings);
                pdfDoc.Save(pdfStream);
                pdfStream.Position = 0;

                //save the pdf file to azure blob storage
                await _azureUploadService.UploadFileStream(directory, pdfFileName, pdfStream, "container");

                pdfDoc.Close(true);
                workbook.Close();
                memoryStreamMergedExcel.Dispose();
                pdfStream.Dispose();
                File.Delete(pdfFileName);
            }
            excelEngine.Dispose();
            return directory + pdfFileName;
        } Looking forward to your support to resolve this issue. Thank you


1 Reply

MA MohamedyusufKhan AhamedMusthafa Syncfusion Team August 10, 2023 08:28 AM UTC

Hi Balu,


We suspect that the image used in the Excel document is in EMF format. XlsIO does have support for the Excel to PDF conversion with EMF image format in the .NET Core platform, and the core platform has only support for png, jpeg, and bmp for Excel to PDF conversion.

 


We have logged a feature report as Support for EMF image in Excel to PDF conversion for the .NET Core platform but do not have any immediate plans to implement this feature in the near future. You can track the status of the feature report through the following feedback link.

 

Track Status: https://www.syncfusion.com/feedback/34516/support-for-emf-image-in-excel-to-pdf-conversion-for-net-core-platform

 

If it is not in EMF format, please share with us the Excel document to validate further. The document will be used only for validation purposes, and it will be maintained privately.


Regards,

Mohamed Yusuf Khan.


Loader.
Up arrow icon