Image shifted depending on the server when converting to PDF

Hello

Context

I’m using Aspose Word 18.2 to convert docx to pdf. My app is deployed in a cluster of 2 servers.

Issues

For the same docx, when I convert it to pdf, some images present on docx are shifter. cf screenshot

server1 server2
OS Debian 9.13 Debian 9.13
Kernel 4.9.0-15-amd64 4.9.0-19-amd64
Java 8 8
jvm 1.8.0_332 1.8.0_332
aspose 18,2 18,2
Bug No yes

Concerned docx in attachment
file.docx (438.0 KB)

Do you have an idea of the cause of this difference?

Thanx

Jerome

@kehrmit sorry I cannot reproduce your issue in my local environment. Since you are facing a discrepancy in between the files generated by the two servers I recommend:

  • Ensure that both servers are running the same version of your code and that they are referencing the same version of Aspose API.
  • Check that all the font dependencies are included in both servers. You can do this by implementing the IWarningCallback interface.
  • Additionally, please update the Kernel version of Server 1. It is currently using the 15th build, whereas Server 2 is using the 19th build. There may have been a small change introduced in the newer build that could potentially fix some integration problems between the API and the system, which could affect the rendering process.

Finally, I recommend to upgrade to the latest version of Aspose.Words, you are using a very old (more than 5 years to the date) version which may contain bugs that are already solved.

Hello.

I make a mistake in my comparison. Shift append with le more recent kernel.
I test on debian 11 and it also work on it!

I use IWarningCallback and found the cause. Font “Wingdings” is substituted by 2 differents fonts, depending on server :

debian 9 with shift : “Font ‘Wingdings’ has not been found. Using ‘Noto Sans CJK JP Light’ font instead. Reason: closest match according to font info from the document.”
debian 11 without shift : “Font ‘Wingdings’ has not been found. Using ‘DejaVu Sans Mono’ font instead. Reason: closest match according to font info from the document.”

But what I don’t understand, when I run command fc-match -s Wingdings, I have same result on the 2 servers

fc-match -s Wingdings
DejaVuSans.ttf: "DejaVu Sans" "Book"
DejaVuSans-Bold.ttf: "DejaVu Sans" "Bold"
DejaVuSans-Oblique.ttf: "DejaVu Sans" "Oblique"
DejaVuSans-BoldOblique.ttf: "DejaVu Sans" "Bold Oblique"
NotoSansCJK-Medium.ttc: "Noto Sans CJK JP" "Medium"

So, why “Noto Sans CJK JP Light” is used instead of "DejaVu "?

It’s hard to say, but the most common reason is that the fonts are not accessible by the Aspose API. I’ll check if there is a logged issue related to this.
If you want to learn more about how Aspose.Words manage fonts, please visit this post.
Alternatively, you can install the missing Windows fonts in your Linux system:

sudo apt install ttf-mscorefonts-installer

Thanks for the interresting link!

ttf-mscorefonts-installer does not contains Wingdings and it change nothing.
Now that i know that the problem comes from this font i will see if i can use another one

PS : For the upgrade of aspose version, I already tried but this caused a problem where all my threads ended up blocking. cf Thread blocked when trying to convert docx to pdf - #4 by alexey.maslov. I was updated direclty from 18.2 to 22.9. Next time I will upgrade by steps, so that I will be able to identify which version cause the issue.

Thanks

1 Like

@kehrmit The difference in font substitution might be caused by different order of font sources. For test I have put DejaVu and Noto fonts into a separate folders and specified font sources like this:

Document doc = new Document("C:\\Temp\\in.docx");

doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsSources(new FontSourceBase[]{
    new FolderFontSource("C:\\Temp\\fonts\\Noto_Sans_JP\\", true),
    new FolderFontSource("C:\\Temp\\fonts\\dejavu-fonts-ttf-2.37\\", true) });

doc.setWarningCallback(new FontSubstitutionWarningCollector());

doc.save("C:\\Temp\\out.pdf");

In this case I get the following warning:

Font 'Wingdings' has not been found. Using 'Noto Sans JP Thin' font instead. Reason: font info substitution.

But if I change the order of font folders, like this:

doc.getFontSettings().setFontsSources(new FontSourceBase[]{
    new FolderFontSource("C:\\Temp\\fonts\\dejavu-fonts-ttf-2.37\\", true),
    new FolderFontSource("C:\\Temp\\fonts\\Noto_Sans_JP\\", true)});

I get the following warning:

Font 'Wingdings' has not been found. Using 'DejaVu Math TeX Gyre' font instead. Reason: font info substitution.

So it looks like on your different servers the fonts are in different order and this causes the difference. Could you please let us know how font source are specified in your code? Is there some difference between the servers?

Regarding your another problem reported here, as Alexey mentioned we cannot reproduce it on our side. So it is difficult to say what is the reason of the problem.

FYI @eduardo.canal

1 Like

Fonts are initialized like that

List<String> folders = Collections.unmodifiableList(Arrays.asList("/usr/share/X11/fonts", "/usr/X/lib/X11/fonts", "/usr/openwin/lib/X11/fonts", "/usr/share/fonts", "/usr/X11R6/lib/X11/fonts", "/Library/Fonts", "/System/Library/Fonts"));
FontSettings.getDefaultInstance().setFontsFolders(folders, true);

I don’t know why previous developper has stop using default fonts location and replace it by this list who do same thing!

Finally, as I find “cause” (real cause in still unknown) of the shift, I can easily fix it by forcing substitution with

fontSettings.setFontSubstitutes("Wingdings", "DejaVu Sans");

@kehrmit It is perfect that you managed to resolve the problem.
By the way, you are using old version of Aspose.Words API. In the new version fontSettings.setFontSubstitutes is not available. In the latest version of Aspose.Words API, you should use TableSubstitutionSettings.
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/#font-availability-and-substitution