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

3 posts, 0 answers
  1. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 02 Jul 2014 Link to this post

    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. Petya
    Admin
    Petya avatar
    975 posts

    Posted 07 Jul 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 01 Oct 2014 in reply to Petya Link to this post

    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. 
Back to Top