Font Questions: Setting default font in SFDT

Hello Friends at SyncFusion,
I am new to SyncFusion technologies and am wondering a few things.
Generally, speaking, the task I am currently working on involves stopping users from pasting text with fonts that aren't supported into the editor. If the user pastes a font with say "Trajan" typeface, (a font we won't support), we want to set a default font, let's say "Arial". Currently, I am using Newton soft to iterate through the SFDT each property in the SFDT. For instance, the styles property looks something like this:
var sfdt = _previewRequest.SFDT;
var data = JObject.Parse(sfdt);
var styles = (JArray)data["styles"];
foreach(JObject style in styles)
{
JObject characterFormat = style["characterFormat"].Value();
var keys = characterFormat.Properties().Select(p => p.Name).ToList();
var fontFam = characterFormat["fontFamily"];
if(keys.Contains("fontFamily"))
{
var fontTokenObj = style["characterFormat"]["fontFamily"];
if(fontTokenObj.ToString() != "Arial")
{
style["characterFormat"]["fontFamily"] = "FOO";
}
}
}
var alteredJsonData = data.ToString();
My questions:
  • Does this sound like a valid way to alter the sfdt json string?
  • Are there any other approaches you might suggest?
  • Is there any documentation around the structure of SFDT itself?
  • The properties I'm seeing on our SFDT object are: sections, characterFormat, paragraphFormat, defaultTabWidth, trackChanges, enforcement, hashValue, saltValue, formatting, protectionType, dontUseHTMLParagraphAutoSpacing, styles, lists, abstractLists, comments, revisions. Will these always be the properties on sfdt?
  • If so, will font always be part of a nested characterFormat property?
Thanks in advance for your reply,
Paul O'Connor

5 Replies

HC Harini Chellappa Syncfusion Team August 21, 2020 01:17 PM UTC

Hi Paul, 

Please find the detail of your query from below table. 

·       Does this sound like a valid way to alter the sfdt json string? 
·       Are there any other approaches you might suggest? 
  
Currently, we are checking on this. Will update further details on or before Aug 25th, 2020. 
Is there any documentation around the structure of SFDT itself? 
  
Currently there is no documentation on SFDT structure. We have planned to include the documentation on this. 
  
You can track its status from below feedback link. 
  
  
The properties I'm seeing on our SFDT object are: sections, characterFormat, paragraphFormat, defaultTabWidth, trackChanges, enforcement, hashValue, saltValue, formatting, protectionType, dontUseHTMLParagraphAutoSpacing, styles, lists, abstractLists, comments, revisions. Will these always be the properties on sfdt? 
  
Yes. It won’t change. 
If so, will font always be part of a nested characterFormat property? 
  
Yes. It comes under characterFormat. 

Regards, 

Harini C 
 
 
 



HC Harini Chellappa Syncfusion Team August 27, 2020 03:16 AM UTC

Hi Paul, 

Currently we don't have any support for font substitution. can you please share how you are considering the font is not supported? please share it in detail.

Regards, 

Harini C 



RF Ricardo Ferreira March 22, 2023 05:52 PM UTC

I'm having the same issue and I know you have ways of doing it but it's not working.

I'm using this code:

// Converts the sfdt to stream
Stream document = WordDocument.Save(data.Content, FormatType.Docx);
Syncfusion.DocIO.DLS.WordDocument doc = new Syncfusion.DocIO.DLS.WordDocument(document, Syncfusion.DocIO.FormatType.Docx);
//Instantiation of DocIORenderer for Word to PDF conversion
doc.FontSettings.SubstituteFont += FontSettings_SubstituteFont;

DocIORenderer render = new DocIORenderer();
//Converts Word document into PDF document
PdfDocument pdfDocument = render.ConvertToPDF(doc);
doc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
render.Dispose();
doc.Dispose();

Stream stream = new MemoryStream();

//Saves the PDF file
pdfDocument.Save(stream);
stream.Position = 0;
pdfDocument.Close();
document.Close();

_logger.LogInformation($"Successfully converted file to PDdF format.");

return new FileStreamResult(stream, "application/pdf")
{
FileDownloadName = data.FileName
};
....

internal void FontSettings_SubstituteFont(object sender, Syncfusion.DocIO.DLS.SubstituteFontEventArgs args)
{
if (args == null)
{
return;
}
Console.WriteLine("Something: ", args.OriginalFontName, args.AlternateFontName);
//Sets the alternate font when a specified font is not installed in the production environment
//If "Arial Unicode MS" font is not installed, then it uses the "Arial" font
//For other missing fonts, uses the "Times New Roman"
if (args.OriginalFontName == "Geneva")
args.AlternateFontName = "Times New Roman";
else args.AlternateFontName = "Arial";
}





SK Selvaprakash Karuppusamy Syncfusion Team March 23, 2023 03:26 PM UTC

Hi Ricardo,


Currently, we are checking this scenario and will update details by March 27, 2023.


Regards,

Selvaprakash K



SK Selvaprakash Karuppusamy Syncfusion Team March 27, 2023 04:14 PM UTC

Hi Ricardo,


The "SubstituteFont" event is triggered when a font(Geneva) is not installed on your production machine. Therefore, if the font(Geneva) is available on your production machine, this event will not be triggered. As a result, Times New Roman will not be changed instead of Geneva.


if the issue occurred when the font(Geneva) was not available on your machine. Please share the input document that you used before converting it to PDF.


If you have any confidential data in your Word document, we recommend that you create a ticket with Syncfusion support.

To create a support ticket: 
https://support.syncfusion.com/support/tickets/create


Loader.
Up arrow icon