Page number in Print document

11 posts, 0 answers
  1. Dhaval patel
    Dhaval patel avatar
    19 posts
    Member since:
    Dec 2009

    Posted 17 Oct 2011 Link to this post

    Hello,

    I prepare data by RadDocument and assign to RadRichTextBox(RadRichTextBox.1Document).
    and then give it to print.

    Is it possible to give page number to printed document.
    also to export to PDF?

    Thanks in advance...
  2. Maulik
    Maulik avatar
    8 posts
    Member since:
    Oct 2011

    Posted 18 Oct 2011 Link to this post

    Even i want to know that stuff :) Waiting for reply!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dhaval patel
    Dhaval patel avatar
    19 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2011 Link to this post

    Please help me !!!!! :(
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 20 Oct 2011 Link to this post

    Hello Dhaval Patel,

    You can add page fields programmatically as described in this forum.
    The page numbers inserted in this way will also be exported to PDF correctly.

    Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Dhaval patel
    Dhaval patel avatar
    19 posts
    Member since:
    Dec 2009

    Posted 21 Oct 2011 Link to this post

    Hello,

    thanks for reply :)

    I have tried to give page number as you said,
    1. create new Class for PagesNumberField.
    2.Override method  GetResultFragment.
    protected override DocumentFragment GetResultFragment()
        {
            int pageNumber = 0;
            int pagesCount = 0;
            if (this.Document != null)
            {
                DocumentPosition position = new DocumentPosition(this.Document);
                position.MoveToStartOfDocumentElement(this.FieldStart);
                SectionLayoutBox sectionBox = position.GetCurrentSectionBox();
     
                pageNumber = sectionBox.PageNumber;
                pagesCount = DocumentStructureCollection.GetChildrenCount(this.Document.DocumentLayoutBox);
            }
            string resultString = "Page " + pageNumber + " of " + pagesCount;
     
            return base.CreateFragmentFromText(resultString);
        }


    but it gives always pagesCount = 1 only..
    so it print like Page 1 of 1, Page 2 of 1, Page 3 of 1..........

    I prepare RedDocument by adding different sections for chart,grid and other information.

    Thanks in advance

  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 25 Oct 2011 Link to this post

    Hello Dhaval Patel,
    This custom field with pages count won't work in headers and footers, as stated in the original thread. We will implement such field in the future, but until then your only option is to insert the total pages number as text.

    Don't hesitate to contact us if you have other questions.

    Kind regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Jonathan
    Jonathan avatar
    7 posts
    Member since:
    Apr 2011

    Posted 15 Aug 2012 Link to this post

    Hello team:

    Is this still the case that these custom fields do not work in headers and footers?

    Thanks!
    Jonathan
  9. Petya
    Admin
    Petya avatar
    975 posts

    Posted 17 Aug 2012 Link to this post

    Hi Jonathan,

    Custom fields can be inserted in the header or footer. The particular implementation of a field containing the count of pages that Boby refered to had a limitation, which prevented that.

    However, I'm happy to inform you that RadRichTextBox already exposes a field with pages count. This is NumPagesField and it can also be inserted in the header or footer. Here is a snippet that shows how to do that:

    radRichTextBox1.Document.Sections.First.Footers.Default.Body.InsertField(new NumPagesField(), FieldDisplayMode.Result);

    Please, do not hesitate to contact us if you have additional questions or comments. All the best,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Patrick
    Patrick avatar
    31 posts
    Member since:
    Aug 2011

    Posted 06 Sep 2012 Link to this post

    Hi,

    The code "radRichTextBox1.Document.Sections.First.Footers.Default.Body.InsertField(new NumPagesField(), FieldDisplayMode.Result);", effectively, put the total pages of the document. The issue that I'm facing is, if I want to map the code with a button and the document is in the footer or header section, it won't put the field in the header/footer cursor position but in the current document position. Here is my snippet:
    Private Sub RRbtnInsertTotalPages_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RRbtnInsertTotalPages.Click
            If editor.IsInHeaderFooterEditMode Then
                Dim CP As Telerik.Windows.Documents.DocumentPosition = New DocumentPosition(Me.editor.Document.CaretPosition)
                CP.GetCurrentSectionBox.GetFooter.Body.InsertField(New NumPagesField(), FieldDisplayMode.Result)
            Else
                editor.Document.InsertField(New NumPagesField, FieldDisplayMode.Code)
            End If
      
        End Sub

    So, to resume, I want to insert the field at the cursor position. If it is in the footer or header section, I want it there.

    Thanks a lot,

    Patrick
  11. Petya
    Admin
    Petya avatar
    975 posts

    Posted 11 Sep 2012 Link to this post

    Hello Patrick,

    You can use the ActiveDocumentEditor property in order to insert NumPagesField at the caret position.
    editor.ActiveDocumentEditor.InsertField(New NumPagesField(), FieldDisplayMode.Result)

    I hope this answers your question!

    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Patrick
    Patrick avatar
    31 posts
    Member since:
    Aug 2011

    Posted 11 Sep 2012 Link to this post

    Thanks. It works fine!
Back to Top
UI for WPF is Visual Studio 2017 Ready