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);
}
}