Images are Vertically flipped when placed in a xlxs converted pdf

Hi,

We are facing an issue when we convert the xlxs file to pdf and try to render the image on them. The rendered image is vertically flipped in PDF.
Here is the code sample.


public static async Task Main()
        {
            var stream = File.OpenRead("AsposeTotalNET.lic");

            Aspose.Pdf.License pdfLicense = new();
            pdfLicense.SetLicense(stream);



            //  Getting Sample Excel file
            Stream xlxsInputStream = File.OpenRead("Sample.xlsx");
            //  Converting to PDF
            Workbook workbook = new Workbook(xlxsInputStream);
            for (int i = 0; i < workbook.Worksheets.Count; i++)
            {
                //fit to one page width
                workbook.Worksheets[i].PageSetup.FitToPagesWide = 1;
                workbook.Worksheets[i].PageSetup.FitToPagesTall = 0;
            }
            Stream pdfStream = new MemoryStream();
            workbook.Save(pdfStream, Aspose.Cells.SaveFormat.Pdf);

            var imageStream = File.OpenRead("img.jpg");

            
            Document document = new Document(pdfStream);
            Page page = document.Pages[1];
            page.Resources.Images.Add(imageStream);
            XImage ximage = page.Resources.Images[page.Resources.Images.Count];
            Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(100, 100, 100 + ximage.Width, 100 + ximage.Height);
            Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });

            page.Contents.Add(new Aspose.Pdf.Operators.GSave());
            page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix));
            page.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
            page.Contents.Add(new Aspose.Pdf.Operators.GRestore());
            document.Save(pdfStream);

            using (var fileStream = File.Create("ConvertedxlsxWithLogo.pdf"))
            {
                pdfStream.Seek(0, SeekOrigin.Begin);
                pdfStream.CopyTo(fileStream);
            }

        }

@cpaperless,

It appears that the issue is more related to the Aspose.PDF API when attempting to render the image on a PDF page. Nevertheless, to accurately evaluate your issue, please zip the XLSX file, image file and final PDF file and share the zipped archive here. We will promptly investigate your issue.

@amjad.sahi
Please find the attached project which contains files as well and will help in reproducing the issue
AsposeSampleConsoleApp.zip (164.0 KB)

@cpaperless,

Thanks for the template Excel file, image file, final output PDF and source code.

I did test your scenario/case using your sample Excel file and application. I noticed the issue with the final output PDF by Aspose.PDF where the image was vertically flipped when placed in the PDF. I simply separated the part regarding Aspose.Cells, tested and generated the PDF file (attached) using the following sample code, it works fine and the output PDF by Aspose.Cells is fine tuned. The data table is rendered Ok.
e.g.
Sample code:

//  Getting Sample Excel file
Stream xlxsInputStream = File.OpenRead("g:\\test2\\AsposeSampleConsoleApp 1\\AsposeSampleConsoleApp\\Sample.xlsx");
//  Converting to PDF
Workbook workbook = new Workbook(xlxsInputStream);
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
       //fit to one page width
       workbook.Worksheets[i].PageSetup.FitToPagesWide = 1;
       workbook.Worksheets[i].PageSetup.FitToPagesTall = 0;
}

workbook.Save("g:\\test2\\AsposeSampleConsoleApp 1\\AsposeSampleConsoleApp\\out1.pdf");

out1.pdf (14.3 KB)

In short, the issue seems with Aspose.PDF part where it was inserting image onto the PDF page. I have informed the respective team and one our fellow colleagues from Aspose.PDF team will evaluate your issue and get back to you soon.

@amjad.sahi

The initial code will also work fine if you remove the cells code and use any existing PDF to place the Image. As per our analysis the image rendering code works fine in all other PDF except the one which is converted from xlsx using Aspose.Cells

@cpaperless,

Thanks for sharing your findings.

Let the Aspose.PDF team evaluate the issue thoroughly and come with their analysis. We will get back to you soon.

@cpaperless

We were able to notice the issue in our environment that the image was flipped in the final output PDF. An investigation ticket as PDFNET-56219 has been opened in our issue tracking system for further analysis. We will look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.