@nikunj.gupta.egon
Hi Nikunj,
I’ve downloaded the “Harvey Balls” font using your link and with it I was able to render the previously provided document “Sample file.docx” to the HTML and PNG with correct pictorial marks, as you initially wanted. I didn’t install this font to my OS Windows. What I did I put this “harvey_balls.ttf” to a separate folder and then specified this folder using the FolderFontSource
and FontSettings
types.
Source code is below. Make sure to adjust the correct and existing paths to the input/output files and folders, and the most important - to set a valid license, because the target page is 4th, while trial mode will allow you to render only first 2 pages. So, the code is below, as a form of unit-test:
[Test]
public void ConvertToHtmlPngWithCustomFontsFolder()
{
// set valid license first!!!!!!!!!
const string filename = "Sample file.docx";
string inputWordsPath = Path.Combine("Valid", "Path", filename);
FileAssert.Exists(inputWordsPath);
string outputHtmlEmbeddedPathTemplate = Path.Combine("Output folder path",
string.Format("{0}-embedded-page{{0}}.html",
Path.GetFileNameWithoutExtension(filename))
);
string outputPngPathTemplate = Path.Combine("Output folder path", string.Format("{0}-page{{0}}.png",
Path.GetFileNameWithoutExtension(filename)));
HtmlViewOptions htmlEmbeddedOpt = HtmlViewOptions.ForEmbeddedResources(outputHtmlEmbeddedPathTemplate);
PngViewOptions pngViewOpt = new PngViewOptions(outputPngPathTemplate);
// "harvey_balls.ttf" should be in this folder!
string harveyBallsFontPath = Path.Combine("Full path", "Fonts", "Harvey Balls");
DirectoryAssert.Exists(harveyBallsFontPath);
GroupDocs.Viewer.Fonts.FolderFontSource fontSource = new GroupDocs.Viewer.Fonts.FolderFontSource(harveyBallsFontPath, GroupDocs.Viewer.Fonts.SearchOption.TopFolderOnly);
GroupDocs.Viewer.Fonts.FontSettings.SetFontSources(fontSource);
using (Viewer viewer = new Viewer(inputWordsPath))
{
viewer.View(htmlEmbeddedOpt);
viewer.View(pngViewOpt);
}
}
The result of this code sample is attached here in a “Sample file-page4.zip” archive — it contains only the 4th page, converted to PNG and HTML. I believe it is the result that you wanted from the beginning.
Sample file-page4.zip (110.4 KB)
Now answer to your question. The situation, when some document was created on the author’s machine and uses some font AAA, and then is processed using the GroupDocs.Viewer on some client’s machine, where font AAA is missing, is typical. In such case GroupDocs.Viewer tries to mimic the MS Word behaviour and substitute this font using some complex font substitution rules: it analyzes the metadata of the document, alternative names of the missing font, settings of the document, settings of the OS, list of all available fonts, installed in the OS and so on. Finally, when by some reason the OS is “clean”, when it has no installed fonts at all (I don’t know how to do this, but may be this is possible somehow), then GroupDocs.Viewer will substitute the free font “Fanwood”, which is embedded directly inside the GroupDocs.Viewer.dll file as a last resort.
At this moment the GroupDocs.Viewer does the font substitution operation “silently” — there are no any messages or events when the font substitution mechanism is activated and which font is missing and onto which is replaced/substituted, and for which exact document. Such feature is hard to implement because it is too unclear, vague, and ambiguous what kind of notification should be emitted, in which form and how they can be utilizing on the client’s side. Also please note that all described above is related to the WordProcessing format family (DOC, DOCX, DOCM, RTF, ODT etc). But there are also much more formats and format families like Excel/Spreadsheet, PowerPoint/Presentation, PDF/XPS and many more, and font processing for them is different.
Hope this code sample and explanation will help. If you have any questions feel free to ask.
With best regards,
Denis Gvardionov