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

RichTextBox - Page number in Raddocument

3 Answers 262 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Cristiano
Top achievements
Rank 1
Cristiano asked on 28 Apr 2014, 02:35 PM
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,

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 29 Apr 2014, 02:40 PM
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.
 
0
Cristiano
Top achievements
Rank 1
answered on 29 Apr 2014, 06:01 PM
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.
0
Petya
Telerik team
answered on 02 May 2014, 10:43 AM
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.
 
Tags
RichTextBox
Asked by
Cristiano
Top achievements
Rank 1
Answers by
Missing User
Cristiano
Top achievements
Rank 1
Petya
Telerik team
Share this question
or