This is a migrated thread and some comments may be shown as answers.

RadDocumentEditor - how to change font size, color, weight...

2 Answers 509 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
C
Top achievements
Rank 1
C asked on 02 Jul 2014, 07:55 PM
How do you change the font size, color, weight, etc. when writing a Microsoft Word document using RadDocumentEditor?

The Word document created has all font in Calibri 6 point normal weight black in Microsoft Word 2010..
It should have different sizes/weights/colors of Calibri and Arial text.

{
RadDocument doc = new RadDocument();
RadDocumentEditor ed = new RadDocumentEditor(doc);

doc.SectionDefaultPageSize = PaperTypeConverter.ToSize(PaperTypes.Letter);
doc.SectionDefaultPageOrientation = PageOrientation.Portrait;
doc.SectionDefaultPageMargin = new Padding(50);

FontFamily fontCalibri = new FontFamily("Calibri");
FontFamily fontArial = new FontFamily("Arial");


ed.ChangeFontFamily(fontCalibri);
ed.ChangeFontSize(8.0);
ed.Insert("Test inserted Calibri");
ed.InsertLineBreak();

ed.ChangeFontFamily(fontArial);
ed.ChangeFontSize(12.0);
ed.Insert("Test inserted Arial");
ed.InsertLineBreak();

ed.ChangeFontFamily(fontCalibri);
ed.ChangeFontSize(15.0);
ed.ChangeFontWeight(FontWeights.Bold);
ed.Insert("Test inserted Calibri 2 bold");
ed.InsertLineBreak();

ed.ChangeFontFamily(fontCalibri);
ed.ChangeFontSize(30.0);
ed.ChangeForeColor(Color.FromRgb(255, 0, 0));
ed.ChangeFontStyle(FontStyles.Italic);
ed.ChangeFontWeight(FontWeights.Bold);
ed.Insert("Test inserted Calibri 2 bold itallic");
ed.InsertLineBreak();

doc.MeasureAndArrangeInDefaultSize();
ExportToWordDocx(doc, "test_report_doc_1.docx");
}

We are using C#, .net 4.5 and Telerik version 2014.2.617.45 of Telerik.Windows.Documents, Documents.Core and Documents.FormatProviders.OpenXmkl


2 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 07 Jul 2014, 12:10 PM
Hello,

The methods of the document editor you are using apply the respective settings to the current paragraph. However, the InsertLineBreak() method does not break the paragraph - it only breaks the line. To achieve the desired result you can insert a new line instead:
ed.Insert(DocumentEnvironment.NewLine);

Additionally, as of next week's LIB two new methods will be included - InsertParagraph() which would break the paragraph and InsertLine(string text) which would insert the string and break the paragraph after it.

I hope this helps.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
C
Top achievements
Rank 1
answered on 01 Oct 2014, 10:37 PM
What was confusing is that the size parameters in individual RadDocument API calls do not mention that the size is in Device Independent Pixels (DIP).   This is in a general note for RichTextBox but not at the individual API call level.

It would help to change API parameter names which have a fixed unit of measure to include the unit of measure in them.  This would follow standard naming practices so that 'size' would be 'sizeDip'.

We use RadDocument to generate a Microsoft Word .docx file in C# code only without creating a RichTextBox control or using XAML. 
Tags
RichTextBox
Asked by
C
Top achievements
Rank 1
Answers by
Petya
Telerik team
C
Top achievements
Rank 1
Share this question
or