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.
@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.
@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:
@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.
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");
@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");
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?