Aspose.words convertsvgtoemf not working in .Net Standard 2.0

Same code was returning EMF for svgs in .net Framework but in standard it is returning png always. With convertsvgtoemf false we are getting same behaviour( font applied) but by setting it true we are getting png without font applied.

using (MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(InputHTML)))
{
    Document doc = new Document(memStream, new Aspose.Words.Loading.HtmlLoadOptions
    {
        Encoding = Encoding.UTF8,
        ConvertMetafilesToPng = false,
        ConvertSvgToEmf = true
    });
}

Does any one have any solution?

@pritam.kumar Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

Hi @alexey.noskov

yes, please find the attachement
Input and Output data:
data.zip (37.9 KB)

issue:

Thanks

@pritam.kumar Most likely the problem on your side occurs because fonts used in the original SVG are not available in the environment where document is converted. I have tested the scenario with the following code in Windows and in Linux without additional fonts:

HtmlLoadOptions opt = new HtmlLoadOptions();
opt.Encoding = Encoding.UTF8;
opt.ConvertMetafilesToPng = false;
opt.ConvertSvgToEmf = true;
opt.WarningCallback = new WarningCallback();

Document doc = new Document(@"/temp/in.html", opt);
doc.Save(@"/temp/out_net_standard_linux.docx");
private class WarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        if (info.WarningType == WarningType.FontSubstitution)
            Console.WriteLine(info.Description);
    }
}

On Linux I see the following warnings:

Font 'Palatino Linotype' has not been found. Using 'DejaVu Sans' font instead. Reason: first available font.
Font 'Georgia' has not been found. Using 'DejaVu Serif' font instead. Reason: table substitution.
Font 'Symbol' has not been found. Using 'DejaVu Sans' font instead. Reason: first available font.

And the output looks the same as your problematic output:
out_net_framework.docx (25.4 KB)
out_net_standard.docx (25.4 KB)
out_net_standard_linux.docx (25.4 KB)

When SVG is converted to metafile, it is actually rendered and the fonts are required for this. If fonts are not availabe, they are substituted. You can implement IWarningCallback, as shown in the code above, to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

@alexey.noskov

Thanks for solution,

It doesn’t able to read my system fonts installed don’t know the exact reason and it was working fine in .NET framework.

It looks like I need to provide fonts path before document conversion.

And one more thing it is directly converting svg to emf and then emf to png? because previously we were getting emf so we had to convert it into png.

@pritam.kumar

Do you test the scenario with .NET Framework and .NET Standard in the same environment?

If you need the SVG image to be inserted into output document as PNG, you should simply disable ConvertSvgToEmf option. In this case SVG is inserted into the final document as SVG with PNG image fallback.

@alexey.noskov yes, same environment

@pritam.kumar Which version of Aspose.Words do you use? Have you tried using the latest 23.11 version of Aspose.Words on your side?

@alexey.noskov For now we are using 23.2 and we haven’t tried 23.11 yet but we will try.

1 Like