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

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

1 Answer 275 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Kittipong
Top achievements
Rank 1
Kittipong asked on 20 Dec 2015, 09:29 AM

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 

http://docs.telerik.com/devtools/aspnet-ajax/controls/wordsprocessing/model/section#rotating-a-section

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

 

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

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 23 Dec 2015, 08:47 AM
Hello,

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.

Regards,
Tanya
Telerik
Tags
WordsProcessing
Asked by
Kittipong
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or