RichTextBox - Page number in Raddocument

4 posts, 0 answers
  1. Cristiano
    Cristiano avatar
    13 posts
    Member since:
    Feb 2012

    Posted 28 Apr 2014 Link to this post

    Hi,
    i am sending the email to ask for help about the RadRichTextBox. Therefore, my problem is that when we add the page number in document, this is written in white on the document.  How to write in black? 
    I would like to know if you have some advice related to my problem.
    Best regards,
  2. Yancho
    Admin
    Yancho avatar
    72 posts

    Posted 29 Apr 2014 Link to this post

    Hi Cristiano,

    Thank you for contacting us!

    If you insert a PageField in the document, it would inherit the style properties of the text it is inserted in. Would you please specify how you insert a PageField in the document - through the UI or a method part of RadRichTextBox's API? Also, could you share more details about you scenario, some screenshots showing the result maybe? This would help us determine the cause of this unexpected behavior and try to provide a solution.

    I am looking forward to your reply.

    Regards,
    Yancho
    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. Cristiano
    Cristiano avatar
    13 posts
    Member since:
    Feb 2012

    Posted 29 Apr 2014 in reply to Yancho Link to this post

    Hi Yancho,

    I have an original document (in bytes) to which I import to a new RadDocument.
    is in this new document that I insert the page number. This is my code:

                        RadDocument document = new RadDocument();
                        Section sectionf = new Section();
                        Paragraph paragraphPageField = new Paragraph() { TextAlignment = RadTextAlignment.Right };
                        PageField pageField = new PageField() { DisplayMode = FieldDisplayMode.Result };
                        FieldRangeStart pageFieldStart = new FieldRangeStart();
                        pageFieldStart.Field = pageField;
                        FieldRangeEnd pageFieldEnd = new FieldRangeEnd();
                        pageFieldEnd.Start = pageFieldStart;

                        paragraphPageField.Inlines.Add(pageFieldStart);
                        paragraphPageField.Inlines.Add(pageFieldEnd);

                        FieldRangeStart numPagesFieldStart = new FieldRangeStart();
                        numPagesFieldStart.Field = new NumPagesField() { DisplayMode = FieldDisplayMode.Result };
                        FieldRangeEnd numPagesFieldEnd = new FieldRangeEnd();
                        numPagesFieldEnd.Start = numPagesFieldStart;

                        paragraphPageField.Inlines.Add(new Span("/"));
                        paragraphPageField.Inlines.Add(numPagesFieldStart);
                        paragraphPageField.Inlines.Add(numPagesFieldEnd);

                        sectionf.Blocks.Add(paragraphPageField);
                        document.Sections.Add(sectionf);

                        doc.Sections.Last.Blocks.AddAfter(doc.Sections.Last.Blocks.Last, paragraphPageField);
                        doc.Sections.Last.Footers.Default.Body.InsertFragment(new DocumentFragment(document));//add the new Raddocument in the document orignal.

    The page number is added to the document, but written in white.

                        The screenshot shows the result of my code.
  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 02 May 2014 Link to this post

    Hi Cristiano,

    First, please note that the InsertFragment() method of RadDocument is deprecated and we recommend switching to RadRichTextBox's or RadDocumentEditor's API. In your case you can assign the Body of the footer as the document in RadDocumentEditor and insert the fragment through it.

    Additionally, adding blocks to a measured document (which is the case when it is shown in RadRichTextBox) is also not recommended, so in case the doc instance in your project is measured, you should consider another approach.

    As to the style, it seems the paragraph in the place where you insert has specific settings which causes the page field to obtain them. I would suggest creating a style which fits your needs and applying it to the paragraph containing the fields:
    StyleDefinition paragraphStyle = new StyleDefinition();
    paragraphStyle.Type = StyleType.Paragraph;
    paragraphStyle.ParagraphProperties.Background = Colors.Red;
    paragraphStyle.ParagraphProperties.TextAlignment = RadTextAlignment.Center;
    paragraphStyle.DisplayName = "paragraphStyle";
    paragraphStyle.Name = "paragraphStyle";
     
    RadDocument document = new RadDocument();
    document.StyleRepository.Add(paragraphStyle);
    Section sectionf = new Section();
    Paragraph paragraphPageField = new Paragraph() { TextAlignment = RadTextAlignment.Right, StyleName = "paragraphStyle" };
      
    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.
     
Back to Top