We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Times - Times New Roman - Different FONT processing

Hello,

I faced an issue in which Excel-generated PDF and Aspose-generated PDF are different in terms of font processing.
In the given sample Excel file, you will find some text fomatted in "Times", and some other formatted in "Times New Roman"
Since "Times" is not in the list of fonts, Excel seems to process it like "Times New ROman" so that users are used to type "Times" in the font selection box for convenience.

The problem is that Aspose behaviour is different so that we are ending up with a incorrect PDF output.

You will find attached:
1. A sample Excel file
2. The Excel-generated PDF
3. The Aspose.Cells-generated one
4. A snapshot illustrating the issue

Here is the C# code snippet I'm using to generate PDF from Excel using Aspose.Cells:

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start.");

string inputFilePath = @"\..\..\Files\TIMES test.xlsx";
string outputFilePattern = @"\..\..\Files\TIMES test - Saved as pdf with Aspose.pdf";

using (MemoryStream inputStream = new MemoryStream(File.ReadAllBytes(Directory.GetCurrentDirectory() + inputFilePath)))
{
using (MemoryStream PDFStream = new MemoryStream())
{
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inputStream);
workbook.CalculateFormula();
workbook.Save(Directory.GetCurrentDirectory() + outputFilePattern, Aspose.Cells.SaveFormat.Pdf);
}
}

Console.WriteLine("End.");
Console.ReadKey();
}
}

Thanks for your support.

Hi Audrey,

Thanks for your posting and using Aspose.Cells.

We were able to observe the issue mentioned by you in your post with your source Excel file, output PDFs generated with Excel and Aspose.Cells and screenshot that highlights the issue. We observed the same by generating the PDF with Aspose.Cells at our end.

We have logged this issue in our database for investigation. We will look into it and see if we could work like MS-Excel and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43117 - Times - Times New Roman - Different FONT processing

I have also attached the output pdf generated with the following code for a reference

C#


string filePath = @“F:\Shak-Data-RW\Downloads\TIMES+test.xlsx”;


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.pdf”);


Hi Audrey,

Thanks for using Aspose.Cells.

We have evaluated this issue further. As the user said, “Times” is not in the list of fonts, so we will find a
font that we have got to show the cell string. This process is
different with what Excel does. And we do not know how Excel does it now.

For now, you can try change cell font name “Times” to “Times New Roman” by code.

Thanks for your response.

Did you mean:

foreach (Aspose.Cells.Worksheet sheet in workbook.Worksheets)
{
foreach(Aspose.Cells.Cell cell in sheet.Cells)
{
Aspose.Cells.Style style = cell.GetStyle();
if (style.Font.Name == "Times")
{
style.Font.Name = "Times New Roman";
cell.SetStyle(style);
}
}
}

Or is there a better way to change all "Times" fonts to "Tiems New Roman" ?

Hi Audrey,

Thanks for posting and using Aspose.Cells.

Yes, you got it right. There is no other better way, you are already using the efficient way of replacing the font name. I have also tested your code and found the pdf generated by it is same as expected.

I have attached the output PDF generated by the code for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\TIMES+test.xlsx”;


Workbook workbook = new Workbook(filePath);


foreach (Aspose.Cells.Worksheet sheet in workbook.Worksheets)

{

foreach(Aspose.Cells.Cell cell in sheet.Cells)

{

Aspose.Cells.Style style = cell.GetStyle();


if (style.Font.Name == “Times”)

{

style.Font.Name = “Times New Roman”;

cell.SetStyle(style);

}

}

}//foreach


workbook.Save(filePath + “.out.pdf”);