I am using "UI for WPF Q1 2016".
I am creating a RadDocument and I set the font to Calibri prior to adding anything:
var doc = new RadDocument();
// can't do real formatting without setting Paged
doc.LayoutMode = DocumentLayoutMode.Paged;
doc.Style.SpanProperties.FontSize = Unit.PointToDip(BodyFontSizePts);
doc.Style.SpanProperties.FontFamily = new System.Windows.Media.FontFamily("Calibri");
Windows.Media.FontFamily("Calibri");
When I save as docx and open in Word, all is good.
When I open a modal dialog based on the RadRichTextBox, the ribbon bar says "Verdana".
When I save my multi-page document as PDF, the first page is obviously Verdana and the second page is obviously Calibri.
All I want is Calibri consistently throughout the document.
Thanks.
-John.
8 Answers, 1 is accepted
Hello Reilly,
I have tested the case according to the provided description and it seems like everything is working as expected and the font properties are preserved. Can you please elaborate more on the exact scenario you have? I would like to ensure we are testing the same setup.
Regards,
Tanya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Tanya,
I am using C# and the "UI for WPF Q1 2016". I set the RadDocument style as shown in the first post, setting the span FontFamily to Calibri, before I add any sections or blocks or anything. Then I build my document as a single section. The only (possibly) "tricky" part is that the first page is a table with one row and two columns.
When I export the document using the DocxFormatProvider, Word says that the font is Calibri everywhere. This is what I expect.
When I export the document using the PdfFormatProvider, the fonts are OBVIOUSLY different on the first page (inside the table) and on the second page (not in a table). If I open the PDF using the "PDF X-Change Viewer", I can select those blobs of text and it says that the page 1 text is Verdana and the page 2 text is Calibri. I had a friend use Adobe and it also shows Verdana and Calibri.
If I open the document in the RadRichTextBox control that I place on a modal dialog, it also shows Verdana and Calibri.
I need the text to have the same font on all pages in all exported formats (docx, PDF, html, rtf). Since PDF shows different fonts, I have to think that the RadRichTextBox sees the same different fonts. But Word sure doesn't.
I have a sample PDF that I can send you, and I also have a sample project.
Thanks for any help.
-John.
If I open the PDF document in Word and let Word convert it, the initial caret position says "Calibri" in Word.The caret position appears to be at the top of the document to the left of the table (i.e. not in the first cell on page 1).
But when I press the right arrow so that the caret moves into the first cell, Word says the font has changed to Verdana.
For what that is worth...
Hi John,
I tested the described scenario using the following code:
string text = @"On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly.
To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can restore the look of your.";
var doc = new RadDocument();
// can't do real formatting without setting Paged
doc.LayoutMode = DocumentLayoutMode.Paged;
doc.Style.SpanProperties.FontSize = Unit.PointToDip(15);
doc.Style.SpanProperties.FontFamily = new System.Windows.Media.FontFamily("Calibri");
RadDocumentEditor editor = new RadDocumentEditor(doc);
Table table = new Table(1, 2);
var paragraph = new Paragraph();
paragraph.Inlines.Add(new Span(text));
table.Rows.First.Cells.First.Blocks.Add(paragraph);
table.Rows.First.Cells.Skip(1).First().Blocks.Add(paragraph.CreateDeepCopy() as Paragraph);
editor.InsertTable(table);
editor.Document.CaretPosition.MoveToLastPositionInDocument();
editor.InsertParagraph();
editor.Insert(text);
editor.Document.CaretPosition.MoveToFirstPositionInDocument();
editor.Delete(false);
this.radRichTextBox.Document = doc;
However, everything seems to be working as expected. I am attaching the .docx and .pdf files that I am getting as a result of exporting the document generated by the code above. Please, let me know if I am missing something from the setup you have.
Regards,
Tanya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Yours looks completely correct.
My code is different in that I build the entire RadDocument, and then later on hand it over to the edit box. In my small application that shows the problem, I export the RadDocument without ever using the edit box.
I converted your example over to build the document and then export it and it works correctly. I'll study the differences.
I wanted to attach my small application as a zip, but the forum will only allow image extensions. So I cheated by adding ".png" to my zip file name. It is still a zip file. Tanya.cs is your code; jjrReflectionStatic1.cs is mine. This application creates both documents, exports them to PDF and DOCX files, and then tells the shell to open them.
Thanks.
I'm not sure why setting the doc.Style.SpanProperties.FontFamily doesn't work for me, but I made it work by explicitly setting the FontFamily for every single Span that I create.
So that's one solution, even if it isn't the best solution.
Thanks.
-John.
Hi John,
I managed to find what is causing you issues - there are two factors preventing the control to apply the required styling. The first one is the table style name. In the sample code you shared, it is set using RadDocumentDefaultStyles.DarkListAccentStyleDisplayName. This property, however, is a placeholder for the different DarkListAccentStyles, and to extract a style name using it, you will need to invoke the GetDarkListAccentStyleNameByIndex() method:
var pageTable = new Table
{
Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(BorderStyle.Single)),
StyleName = RadDocumentDefaultStyles.GetDarkListAccentStyleNameByIndex(1)
};
This method can be used with parameter values between 1 and 6 to produce the different style names.
The second factor is that, because of an issue in the style resolving, the table styles do not inherit the span properties defined in the document default style. This issue is logged on our backlog and you can subscribe to track its status using the related public item: RichTextBox: Text does not inherit style properties from document DefaultStyle when it is inside table. In this item, you will also find a sample code demonstrating how you can work around that issue.
Hope this information is helpful.
Regards,
Tanya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks, Tanya, for sticking with me until the end.
I really appreciate the great help!
Best regards,
-John.