Font missmatch between Word, PDF, and image types

Hi Aspose Team,
we face a problem when converting word to any image format (JPEG, PNG). We are using template word document using document builder. The content inserted in the word contains an SVG in an HTML string. The SVG has text in it with different font sizes. The SVG looks fine in the word document and when the word document is converted to PDF, but when the word document is converted to any image formats, the resulting images have non-desirable font changes compared to word and PDF.
I attached a simple .NET console application. Please note that the images contain unreasonable big fonts in places where only a 0.5 pt increase is expected.
Thank you for your help and time!
SampleConsoleApp.zip (280.4 KB)

@ottap

It seems you are experiencing font mismatches when converting a Word document containing SVG elements to image formats like JPEG or PNG. This issue can arise due to how fonts are handled during the conversion process.

To address this, you can utilize the FontSettings class in Aspose.Words, which manages font sources and font substitution. When Aspose.Words encounters a font for the first time, it retrieves the necessary font information from the defined font sources. If the required font is not available, it may substitute it with a different font, which could lead to the discrepancies you are observing in the image output.

Here are some steps you can take to mitigate the font mismatch issue:

  1. Define FontSettings: Create an instance of FontSettings and specify the font sources that include the fonts used in your SVG. This can help ensure that the correct fonts are used during the conversion process.

    FontSettings fontSettings = new FontSettings();
    fontSettings.SetFontsFolder("path_to_your_fonts_folder", true);
    Document doc = new Document("your_document.docx");
    doc.FontSettings = fontSettings;
    
  2. Check Font Availability: Ensure that all fonts used in the SVG are available in the specified font sources. If a font is missing, Aspose.Words will substitute it, which may lead to unexpected results.

  3. Test with Different Formats: If the issue persists, try converting the document to different image formats to see if the problem is consistent across all formats or specific to one.

  4. Update Aspose.Words: Ensure you are using the latest version of Aspose.Words, as updates may include fixes for font handling and conversion issues.

By following these steps, you should be able to improve the consistency of font rendering when converting your Word document to image formats. If the problem continues, consider sharing a minimal reproducible example for further assistance.

If you have any additional questions or need further clarification, feel free to ask!

@ottap
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27950

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@ottap We have completed analyzing the issue and decided to close it as Not a Bug.
In the provided document, there is indeed a minor difference in font size (7.125 pt vs. 7.5 pt). When rendering the document into an image, we use the standard GDI+ mechanism, which is highly sensitive to resolution. At the default resolution (96 dpi), this results in the text appearing slightly thicker. Apparently, this is the result of some error in rounding font sizes inside GDI+, and unfortunately, we have no control over this behavior.
If set the resolution to 350 dpi, the issue disappears.
That said, it’s worth noting that at certain resolutions, the positioning of letters may shift slightly. This appears to be due to text alignment inaccuracy within GDI+.

Workarround:

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.Resolution = 350;
doc.Save("out.png", options);

The issues you have found earlier (filed as WORDSNET-27950) have been fixed in this Aspose.Words for .NET 25.4 update also available on NuGet.