Hi!
I am using RadWordsProcessing and load Word`s file.
RadFlowDocument document;
DocxFormatProvider fileFormatProvider =
new
DocxFormatProvider();
string
fileName = Server.MapPath(
"./Data/Document.docx"
);
using
(FileStream input =
new
FileStream(fileName, FileMode.Open))
{
document = fileFormatProvider.Import(input);
}
RadFlowDocumentEditor editor =
new
RadFlowDocumentEditor(document);
Text in the file is written in Times New Roman font.
But when exporting to pdf, the font changes to Segoe UI font.
Why?
3 Answers, 1 is accepted
The code seems all right. I tried to reproduce the issue described, but in my example, I haven't noticed such behavior. Could I ask you to send me the document so I can test it locally and try to find the reason for the issue you are experiencing?
Regards,
Martin
Progress Telerik

any updates on this? i'm encountering the same issue.
01.
DocxFormatProvider DocxProvider =
new
DocxFormatProvider();
02.
RadFlowDocument DocX =
new
RadFlowDocument();
03.
string
TemplatePath = Path.Combine(Environment.CurrentDirectory, @
"..\CRS\wwwroot\LetterTemplates\VictimNotification.docx"
);
04.
05.
using
(Stream input = File.OpenRead(TemplatePath))
06.
{
07.
DocX = DocxProvider.Import(input);
08.
}
09.
10.
PdfFormatProvider provider =
new
PdfFormatProvider();
11.
byte
[] renderedBytes =
null
;
12.
13.
using
(MemoryStream ms =
new
MemoryStream())
14.
{
15.
RadFixedDocument fixedDocument = provider.ExportToFixedDocument(DocX);
16.
provider.Export(DocX, ms);
17.
renderedBytes = ms.ToArray();
18.
}
19.
20.
return
File(renderedBytes,
"application/pdf"
,
"Sample.pdf"
);
Hello Tommee,
I am attaching a sample project converting a DOCX document with Times New Roman font set to a PDF document and the font is imported and exported as expected. Please, feel free to modify it in a way closer to your scenario.
In order to deeper investigate this case, I would like to ask you to open a new support ticket and send us the document causing this behavior. I must assure you we treat all client files in a strictly confidential manner and for testing purposes only.
Looking forward to hearing from you.
Regards,
Martin
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
Hello Cory,
In order to be able to investigate the case further and continue the conversation in a more private thread, I would like to ask you to open a new support ticket regarding the issue you are facing. If possible please share for inspection the sample HTML document that reproduces the behavior. I can assure you that anything shared by our clients is treated with strict confidentiality and is used for testing purposes only (as per our EULA section 11).
Thank you in advance.
Yoan
Having the same issue here. .docx file has Times New Roman on one paragraph and calibri for other paragraphs, but when converted to PDF, the entire pdf has just one font that looks like calibri/arial.
I'll keep searching for a solution and will try the demo project you have attached, thanks!
UPDATE: The demo project works and properly keeps my document's Times New Roman font, but when I copy the demo code into my app, the EXACT SAME CODE, it loses the Times New Roman font. My app however has many more "using " statements at the top of it, so I think one of the other telerik libraries is conflicting somehow. I'm trying to isolate it down now....
UPDATE2: Yep, I converted your demo code to use the Telerik.Documents.Core packages instead of the Telerik.Windows.Documents.Core packages, and that now causes your demo to break and not retain the Times New Roman font.
So, it seems that in order to retain the fonts, you have to use the older outdated Windows specific libraries, not the newer .NET cross-platform libraries. At least that's what it seems like so far....
Hello Andrew,
Thanks for the follow-up.
Based on the provided description, it is very likely that the results you are experiencing are caused by a font limitation of the PdfProcessing library, specifically with the .NET Standard assemblies/packages. You can read more about this in our Cross-Platform and Fonts articles.
In short, the PdfProcessing library needs to have access to the data of the fonts used in the original DOCX document so that it can properly read them and add them to the result PDF file. The .NET Framework version of PdfProcessing comes with out-of-the-box functionality to read fonts, however, the .NET Standard version does not have such capabilities.
This is why in .NET Standard scenarios, to allow the library to create and use fonts, you need to manually provide an implementation that can serve as a workaround. You can go with one of the following options:
- Implement a FontsProvider - automatically searches for the fonts in your system.
- Manually register the fonts - you need to provide an explicit path to each font file.
I hope this resolves the setbacks on your end.
Regards,
Yoan
That absolutely worked! I clicked on your "Implement a FontsProvider" link, and copied the entire FontsProviderBase class from that page into the demo script, and then added two lines you indicate to the top of the Main() function:
Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;
and then just found my Times font and added that to the FontsProviderBase:
else if (fontProperties.FontFamilyName == "Times New Roman")
{
if (fontProperties.FontStyle == FontStyles.Italic && fontProperties.FontWeight == FontWeights.Bold)
{
fontFileName = $"timesbi.ttf";
}
else if (fontProperties.FontStyle == FontStyles.Italic)
{
fontFileName = $"timesi.ttf";
}
else if (fontProperties.FontWeight == FontWeights.Normal)
{
fontFileName = "times.ttf";
}
else if (fontProperties.FontWeight == FontWeights.Bold)
{
fontFileName = $"timesbd.ttf";
}
}
and then the PDF rendered the Times New Roman font properly! Thanks!
Having a bit of an issue getting some symbols to show up: ☐☐☐☐☐☐ Even though those boxes are listed as "Segoe UI Symbol" and I'm pointing the script to segoeui.ttf, they're not showing up in the PDF, but I'm sure that's a simple solution, I'll keep trying, but at least your solution describes precisely how to implement specific fonts during the conversion.
Thanks for those links! :)
EDIT: I solved the empty box issue by just switching to an actual WingDing checkbox symbol and adding WingDing.ttf to the supported fonts. :)
Hi, Andrew,
I am glad to hear that the suggested solution by my colleague, Yoan, works for your scenario.
It is important to note that the fonts provider should be extended with all the fonts used in the specific documents you load. In case of encountering a weird symbol, make sure that you have provided the font for it in the fonts provider.
Should you have further questions please let me know.