Aspose.PDF 21.3.0 .NET - PngDevice generating different images on Linux vs Windows. Everything looks "bold" on Linux

Hello,

We are trying to migrate our project from Windows to Linux Containers and we came across an issue where given all the same parameters and same file, different PNG images are being generated on Windows and on Linux when using PngDevice.Process().

The interesting part is that the final PDF document that is generated on both OS’s looks identical but there is also a difference when comparing bytes. That is not really an issue to us since the final PDF looks identical, however the PNG images being generated on Linux look different and far worse than the ones generated on Windows. This is an issue since we display these PNGs to customers as they manipulate the document. This difference in images is more obvious when the document is zoomed in and everything appears more bold from Linux.

Please see the small sample project I’ve created with an included PDF document that reproduces this issue. Simply take the project, restore dependencies, and run on Windows, and then do the same on Linux to see the difference in outputs.

Another issue with this difference in output is that the images generated on Linux end up being 2.5X bigger while still being the same resolution as the ones generated on Windows.

I believe this is a bug and any help or work arounds to make the PNG image look the same is appreciated. I have already tried increasing the resolution on the PngDevice to 400 which makes it looks pretty similar but still lower quality than on Windows, and this increases the file size from 200kb on Windows to 1500kb on Linux which isn’t sustainable.

Also the only fonts being used in this document are the following, and I’ve made sure Microsoft’s TrueType fonts are installed in the Linux Container.

Arial-BoldMT
Calibri
Verdana-Bold
Verdana

Thank you

Image comparisons:

Linux:
1-linux-output.png (510.8 KB)

Windows:
1-windows-output.png (213.8 KB)

Diff:
png diff.png (10.8 KB)

Final PDF output documents:
linux-output-pdf.pdf (286.6 KB)
windows-output-pdf.pdf (293.7 KB)

Sample Project:
comparing-windows-linux.zip (250.6 KB)

@mkondra

We have tested the scenario in our environment i.e. Linux (Ubuntu). We were unable to notice any issue in the output image. Are you facing this issue with every PDF file or just this specific document that you have shared?

Converted_Image_1.png (495.3 KB)

Would you kindly make sure that the Microsoft Fonts are installed in “/usr/share/fonts/truetype/msttcorefonts” directory? Also, please try to upgrade the libgdiplus package to the latest version. Please feel free to let us know in case you still notice any issue by sharing complete details of your Linux environment (OS Name and Version).

Hello @asad.ali,

I am facing this issue with every PDF I’ve tried so far (I’ve tried a couple), and those PDFs use other fonts as well like Helvetica which I believe should be defaulting to Arial.

I’m facing this issue on Ubuntu 18.04, however since you weren’t able to reproduce it I decided to make a fresh Ubuntu 20.04 installation to eliminate any environment variables. If it makes a difference I am running Ubuntu on top of WSL2 engine in Windows.

After I made a new Ubuntu 20.04 installation I ran the following commands to install .NET, libgdiplus, fontconfig, mscorefonts, and also I installed vista fonts just in case for Calibri.

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update;
sudo apt-get install -y apt-transport-https &&
sudo apt-get update &&
sudo apt-get install -y dotnet-sdk-5.0

sudo apt install libgdiplus
sudo apt install fontconfig
sudo apt-get install ttf-mscorefonts-installer

sudo apt-get install fontforge
sudo apt-get install cabextract
wget https://gist.github.com/maxwelleite/10774746/raw/ttf-vista-fonts-installer.sh -q -O - | sudo bash
sudo fc-cache -f -v

I then copied over my sample project and ran it, and still got the same issue.

To verify here is the output of my /usr/share/fonts/truetype/msttcorefonts directory:
image.png (9.0 KB)

Here is also the output for fc-match for each of the 4 fonts to confirm that they are being found by the system:
image.png (3.5 KB)

I also tried the steps described here 14.04 - How to get Calibri font to display nicely - Ask Ubuntu and created a .fonts.conf file and also tried the 10-antialias.conf step of setting antialiasing to false, and it hasn’t helped.

Is there any other sort of setup I’m missing to get this to work correctly like it works for you?

Thank you

@mkondra

Could you please share the .NET Core version that you are using?

@asad.ali
I’m using .NET (Core) 5.0.201

Here is the full output of dotnet --info:

.NET SDK (reflecting any global.json):
Version: 5.0.201
Commit: a09bd5c86c

Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/5.0.201/

Host (useful for support):
Version: 5.0.4
Commit: f27d337295

.NET SDKs installed:
5.0.201 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

@mkondra

We have logged an investigation ticket as PDFNET-49692 in our issue tracking system for further investigation on this scenario. We will further look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you @asad.ali.

Can you please share what Linux environment and .NET Core version you guys used to test this and create the good looking image “Converted_Image_1.png” in your first reply?

Maybe we can use the same environment and version for now to produce good images while this is being investigated.

@mkondra

We tested in Ubuntu 15.04 x64 environment. We performed testing using both .NET and Java APIs and did not notice any issue. At the moment, the issue seems related to specific environment and that is why we logged a ticket for detailed investigation.

Great, thank you for the info and your time. We will be waiting for the results of PDFNET-49692 then.

Hello, we are facing the exact same issue on ubuntu.20.04-x64 using NET Core 3.1.
Is there any update on the progress of a fix for this?

@loumondelaers

We are afraid that the earlier logged issue is not yet resolved. However, we have recorded your concerns and will surely inform you once the ticket is closed.

We apologize for the inconvenience.

Hello, do you have any information regarding this issue?

@endyz

The issue is currently under the phase of the investigation and as soon as it is completed, we will be able to share some feedback in this forum thread. Please spare us some time.

We apologize for the inconvenience.