SVG with embedded smart symbols are rendered differently in Word and PDF

Hi Team,

I am trying to build a report using a SVG content with few smart symbols embedded in it. When I compared the Word and PDF files the output turned out to be different. Requesting your assistance to help resolve this issue.

WORD output

PDF output

AsposeSmartSymbols.zip (26.6 KB)

@ottap Unfortunately, I cannot reproduce the problem on my side. I have simplified your code to the following:

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

var engine = new ReportingEngine();
engine.BuildReport(doc, new string[] { File.ReadAllText(@"C:\Temp\svg-sample.html")  }, new string[] { "Content" });

doc.Save(@"C:\Temp\Docx_V3.docx");
doc.Save(@"C:\Temp\Docx_V3.pdf");

And here are output document produced on my side:
Docx_V3.docx (23.8 KB)
Docx_V3.pdf (19.6 KB)

As you can see in both cases symbols look fine. Could you please attach the problematic PDF document produced on your side here for our reference?

@alexey.noskov Would it be possible for you to temporarily remove the smart symbol fonts from 'c:\windows\fonts" location in a windows system. That way it is possible to reproduce the issue. Let me know in case you need any additional information from my side. I plan to share the PDF file you asked for in a little while.

Thanks.

@ottap The problem is still not reproducible. As I can see only Times New Roman font is used for rendering the document.

I have tested with the following code:

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] {new FolderFontSource(@"C:\Temp\fonts", true) });

Document doc = new Document(@"C:\Temp\TemplateV3.docx");
doc.WarningCallback = new FontSubstitutionWarningCallback();

var engine = new ReportingEngine();
engine.BuildReport(doc, new string[] { File.ReadAllText(@"C:\Temp\svg-sample.html") }, new string[] { "Content" });

doc.Save(@"C:\Temp\Docx_V3.docx");
doc.Save(@"C:\Temp\Docx_V3.pdf");
internal class FontSubstitutionWarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        if (info.WarningType == WarningType.FontSubstitution)
            Console.WriteLine(info.Description);
    }
}

The specified C:\Temp\fonts older contains only Times New Roman font. Here is the output: Docx_V3.pdf (19.6 KB)

@alexey.noskov Please refer to this updated code.
AsposeSmartSymbols.zip (2.0 KB)

Temp folder
Temp.zip (86.0 KB)

Let me try to elaborate the scenario briefly,

  1. The source template file has a text with smart symbols specified, but this particular smart symbol font does not exists in c:\windows\fonts folder.

  1. Now, I am placing this smart symbol font inside c:\temp\fonts folder

  2. I generated a Word and PDF files, which gives me a different output

The word is not able to pick up the specified smart symbols font assuming that it does not exist in c:\windows\fonts folder

Whereas the PDF file is able to display the smart symbols font although it is does not exist in c:\windows\fonts folder

Now, if I remove the smart symbol font from c:\temp\fonts folder both the output in docx and pdf is similar.

Let me know, in case you need any additional information from my side.

Thanks.

@ottap The behavior is expected. When you place smart symbol into c:\temp\fonts folder and use this folder as an only font source for document rendering, Aspose.Words uses this font as the only available font. If specify several font sources like this:

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"C:\Temp\fonts", true) });

Aspose.Words will look for fonts in the system also, and the document is rendered properly:
Docx_V3.pdf (22.6 KB)

I am not sure why MS Word cannot resolve the smart symbol font on your side. You can try embedding the font into the document like this:

doc.FontInfos.EmbedTrueTypeFonts = true;
doc.FontInfos.SaveSubsetFonts = false;
doc.Save(@"C:\Temp\Docx_V3.docx");

In this case DOCX looks the same as PDF:
Docx_V3.docx (1.9 MB)

@alexey.noskov Can you help me understand how the PDF is able to resolve the smart fonts embedded inside the SVG while MS Word cannot? The additional settings you provided works if smart fonts are not embedded inside the SVG.
Thanks.

@ottap There is no font embedded into SVG. There is style with Smart Symbols font specified:

<text x="0" y="-1.907226563" class="f4-2486">%</text>
.f4-2486{font-family:Smart Symbols;font-size:9px;fill:#000000;}

If the font is available Aspose.Words uses it for rendering, if not the font is substituted. MS Word must do the same and it does. If install Smart Symbols font on the machine where the document is viewed, the Smart Symbols characters are displayed properly:

@alexey.noskov Thanks for your response. Let me try describing this specific scenario where I’m only concerned about the PDF output and image that is generated from the document. Our application picks up the fonts from a specified folder location.

So, when the document is converted to PDF it seems to taking the fonts from that particular folder. Now when I try converting the same document to Jpeg it does not take the from that specified folder location.

All I’m trying to understand is why PDF format is able to display smart symbol fonts provided it is present in that specific folder, whereas when I try converting the document to image it does not display smart symbol fonts properly.

Is there any additional settings available in Aspose using which I can explicitly specify the font folder location? I think my program does not recognize the external folder where smart symbol font is location when I try to convert the document to images.

 FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new FolderFontSource(@"C:\Temp\fonts", true) });
 
 Document doc = new Document(@"C:\Temp\TemplateV3.docx");
 doc.FontInfos.EmbedTrueTypeFonts = true;
 doc.FontInfos.SaveSubsetFonts = false;
 doc.WarningCallback = new FontSubstitutionWarningCallback();
 
 var engine = new ReportingEngine();
 engine.BuildReport(doc, new string[] { File.ReadAllText(@"C:\Temp\svg-sample.html") }, new string[] { "Content" });
 
 var base64ImageList = new List<string>();
 
 if (doc != null)
 {
     var options = new ImageSaveOptions(SaveFormat.Jpeg);
 
     for (var i = 0; i < doc.PageCount; i++)
     {
         using var stream = new MemoryStream();
         stream.Position = 0;
         options.PageSet = new PageSet(new PageRange(i, i));
         doc.Save(stream, options);
         stream.Position = 0;
 
         var image = SKData.Create(stream);
         var base64String = Convert.ToBase64String(image.ToArray());
 
         Console.WriteLine(base64String);
 
         base64ImageList.Add("data:image/jpeg;base64, " + base64String);
     }
 }
 
 doc.Save(@"C:\Temp\Doc_SS.pdf");

Temp.zip (106.5 KB)

Thanks.

@ottap Unfortunately, I cannot reproduce the problem on my side. I have used the following code:

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new FolderFontSource(@"C:\Temp\fonts", true) });

Document doc = new Document(@"C:\Temp\TemplateV3.docx");
doc.WarningCallback = new FontSubstitutionWarningCallback();

var engine = new ReportingEngine();
engine.BuildReport(doc, new string[] { File.ReadAllText(@"C:\Temp\svg-sample.html") }, new string[] { "Content" });

doc.Save(@"C:\Temp\Docx_V3.jpeg");
doc.Save(@"C:\Temp\Docx_V3.pdf");

Here are image and PDF output files:
Docx_V3.jpeg (32.2 KB)
Docx_V3.pdf (5.8 KB)

Thanks for the response. This is re produced consistently at our end using the same code you provided. We ran the test in the Windows machine and using Aspose.Words version 24.4.0. What is the version of Aspose.Words you are using and Is it a windows environment where you ran this test?

@ottap Yes I used the latest 24.4 version of Aspose.Words for testing and testing environment is Windows machine.