how to start insert text in a new DOCX page A4 ?

2 posts, 0 answers
  1. Kittipong
    Kittipong avatar
    5 posts
    Member since:
    Sep 2013

    Posted 20 Dec 2015 Link to this post

    I use there code to make a docx file


    RadFlowDocument document = new RadFlowDocument();
    RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
    editor = new RadFlowDocumentEditor(document);
    editor.insertText("this is page 1 ");
    // but the problem is I want to insert text in another A4 page like
    editor.insertText("this is page 2 ");

    According to the document telerik I found that we can set up "section" for A4 page

    but I think I don't understand how to use it please help !!
    Section section = new Telerik.Windows.Documents.Flow.Model.Section(document);
             section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(40, 10, 40, 10);
             section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);//WindowsBase assembly should be referenced.
             editor.InsertText(("Page 2 !!"));


    and is it possible that we know what is the current page number before "insertText" ?

  2. Tanya
    Tanya avatar
    583 posts

    Posted 23 Dec 2015 Link to this post


    The page size is a property of the Section class and could be modified following the approach you already found in our documentation. With RadFlowDocumentEditor you can create and insert a section in the document at the same time as demonstrated in the code snippet below. The InsertSection() method creates a new Section and inserts in the current RadFlowDocument instance. The method returns the Section object and you can use it for further customizations. Here is how I modified the code in order to achieve the desired goal:
    editor.InsertText("Page 1");
    document.Sections.First().PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);
    Section section = editor.InsertSection();
    section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(40, 10, 40, 10);
    section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);
    editor.InsertText("Page 2");

    Please, note that inserting text into the empty document automatically creates a Section and a Paragraph where the text will be placed.

    RadWordsProcessing is independent of UI and has no notion about how the document should look like. In other words, it is not clear how many pages will be filled and at which page a document element will take place. Thus, it is not possible to find the number of the currently modified page. 

    Hope this helps.

Back to Top