Letters are overlapped in Excel to image

Hi Aspose.Cells team,

We are currently facing issue of text being overlapped in the image which is created from excel.

We are using .Net and please find the code below

for (int i = 0; i < headerRows.Count - 1; i++)
{
int startRow = headerRows[i];
int endRow = headerRows[i + 1] - 1;

// Define the print area for each segment
string printArea = $"A{startRow + 1}:W{endRow + 1}";
worksheet.PageSetup.PrintArea = printArea;
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;

var imageOptions = new ImageOrPrintOptions
{
    ImageType = Aspose.Cells.Drawing.ImageType.Png,
    OnePagePerSheet = true
};
var sheetRender = new SheetRender(worksheet, imageOptions);


using (var stream = new MemoryStream())
{
    sheetRender.ToImage(0, stream);
    byte[] imageBytes = stream.ToArray();
    string imgBase64 = Convert.ToBase64String(imageBytes);

    // Embed the image in HTML
    string header = headers[i];
    body += $"<img src='data:image/png;base64,{imgBase64}' alt='{header}' style='max-width:100%' />";
}

}

Please find the attached image as outcome of this code.
Aspse.CellsImageIssue.png (165.0 KB)

@agarwalashwani2020

To figure the issue out, we need the template file to reproduce the issue. Please zip your template Excel file and attach it here. We will look into it soon.

myFile.7z (29.9 KB)

Hi Johnson,

Thanks for your response. I have attached the Zip file(Excel file inside) with this thread.

@agarwalashwani2020
By testing on the latest version v24.9 using sample files and the following sample code, we can obtain the correct results. Please refer to the attachment.
out_net.jpg (818.8 KB)

The sample code as follows:

Workbook wb = new Workbook(filePath + "myFile.xlsx");
Worksheet sheet = wb.Worksheets[0];
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions
{
    ImageType = Aspose.Cells.Drawing.ImageType.Png,
    OnePagePerSheet = true
};
SheetRender sheetRender = new SheetRender(sheet, imageOptions);
sheetRender.ToImage(0, filePath + "out_net.png");

We recommend you to kindly try using our latest version,
Aspose.Cells for .NET 24.9.

Hi,

I have updated the latest version as per your recommendation but i still get the same result.

Please find the attached resulted image.
AsposeLatestVersion_OverlapLetters_NotWorking.png (156.6 KB)

@agarwalashwani2020
Would you like to provide your runnable test code? We will check it soon.

Hi

Console1.zip (winows console C# Application)
snapshot of output as below

Aspose_on_window.PNG (93.3 KB)

Aspose-excel-sheet-images.zip (dot net 8 aws lambda)
snapshot of output as below
Aspose_on_aws_lambda.png (111.9 KB)

findings are as below

  1. windows console application output images have no issues of overlapping text.
  2. dot net AWS lambda output images have issues of overlapping text.

Please see the below sample applications

ConsoleApp1.zip (1.2 MB)

Aspose-excel-sheet-images.zip (185.4 KB)

@agarwalashwani2020
1,Please confirm font “Garamond” installed on your aws lambda server. Configuring Fonts for Rendering Spreadsheets|Documentation
2,We need some time to build the testing environment.

We are using DotNet AWS Severless Lambdas, so the server is not known to us, which is the reason we can’t install Garamount font on the server.

Behind the scenes, AWS Lambda runs on Linux OS.

@agarwalashwani2020

  1. Please copy the fonts to the server and config fonts as: Configuring Fonts for Rendering Spreadsheets|Documentation. We only need to find the font files to measure and draw text.

  2. If you are using AWS Lambda runs on Linux OS, please use Aspose.Cells assembly from netX.0 folder(s) and not from netX.0-windows folder(s).

Hi @agarwalashwani2020
For this issue, we tested on linux docker, net8, the problem can be repeated.
For a normal docker image, we recommend adding a single line to the Docker file:
COPY fonts/ /usr/share/fonts
You put the “fonts” directory in the local project directory, and then you put the font files into the “fonts” directory, and the fonts is installed into the Linux image.
In this case, the font in Excel file is “Garamond”, it can be found in windows font path.
This “SolutionA” copies fonts to linux docker, because Linux has very few default fonts. This solution ensures that your program can find the desired font from the Linux system path.
SolutionA.png (42.9 KB)

However, in an AWS serverless environment, we are not sure if the above solution A is easy for you to implement.
You can also put the “fonts” directory in the local project directory, and run:
Aspose.Cells.FontConfigs.SetFontFolder(“fonts”, true);

This “SolutionB” do not copy any font file to linux docker, just make sure the program can find the font from the project path.

We recommend using solution A. if your ASW serverless project can not upload fonts to AWS, Please Use Solution B and let us know your results, thanks.

SolutionB.png (40.3 KB)

For your reference, here are sample projects for solution A and B, which can be run in the Docker desktop environment.

DockerNet8_SkiaSharp8.zip (2.2 MB)

DockerNet8_SkiaSharp9.zip (1.4 MB)