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

Layout of a specific page

8 Answers 33 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Marcílio
Top achievements
Rank 1
Marcílio asked on 10 Dec 2018, 01:22 PM
Hello everyone!
How do I change the layout of a specific page of my RadDocument?

8 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 13 Dec 2018, 11:48 AM
Hi Marcílio,

RadDocument is the base class representing the document of RadRichTextBox. The product category of this forum is dedicated to Telerik Document Processing libraries, so I am not sure which component that you are using. Can you please specify the product and elaborate more on what exactly you would like to change so I can better assist you?

Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Marcílio
Top achievements
Rank 1
answered on 13 Dec 2018, 03:51 PM
Hi martin

Sorry for the simple question. I'll be more specific!

I have a document created with RadDocumentEditor (created with a combination of other merged RTF documents). But in my application, the user must choose different templates of documents pre-configured for printing this "merged documents". Templates have different page sizes and margins for each even / odd page. So, I need to get this document created and apply specific page margins and page sizes on each page generated by RadDocumentEditor. This final formated document will be sent to the printer.

I hope I have made my doubt clear.
0
Marcílio
Top achievements
Rank 1
answered on 13 Dec 2018, 07:54 PM
To help to understand better the issue, follow a schematic draw of the objective.
0
Martin
Telerik team
answered on 18 Dec 2018, 09:05 AM
Hi Marcílio,

To achieve the desired behavior, you can benefit from the functionality of Section class. The Section exposes several properties that allow you to customize the layout of the elements placed underneath it. Please take a look at our Section article where you can find detailed information on the matter.

I hope that this helps.

Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Marcílio
Top achievements
Rank 1
answered on 19 Dec 2018, 12:16 PM

Hi Martin,

I had already researched about the Section class. However, I have not been able to reach the specified goal yet. How can I trigger the creation of a new section as the pages are being created? I have not found any events that trigger as soon as a new page appears in the document. Can you put me in the right direction?

0
Tanya
Telerik team
answered on 21 Dec 2018, 04:47 PM
Hello Marcílio,

There is no specific event notifying about the creation of a page. Actually, the Open XML format allows you to specify the properties of a page through the Section and all the pages in a single section have the same settings. If you would like to separate the pages on different sections so you can control their properties separately, you can do this using continuous section breaks. What you would need to do is to move the caret to the last position in the page using the MoveTo~() methods of the caret position and insert a section break there:
this.radRichTextBox.InsertSectionBreak(SectionBreakType.Continuous);

Once you have divided the pages into different sections, you can control their properties through the members of the Section class.

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Marcílio
Top achievements
Rank 1
answered on 26 Dec 2018, 07:28 PM

Hello Tanya,
Thanks for the help. But I'm still stuck with this issue...
Follow the code I'm using. The creation of a section for each page of the document is not working. With the folowing code all the sections are created in the same page (In the page two to be more specific). The combination of the two documents It's working perfectilly. Can you explain to me what I'm doing wrong?

01.var document = new RadDocument();
02.document.LayoutMode = DocumentLayoutMode.Paged;
03.IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension("rtf");
04. 
05.var merger = new RadDocumentMerger(document);
06.var options = new AppendDocumentOptions();
07.options.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.RenameSourceStyle;
08.options.FirstSourceSectionPropertiesResolutionMode = SectionPropertiesResolutionMode.SourceStartContinuous;
09.var files = new string[] { "rtf1.rtf", "rtf2.rtf" };
10.foreach (string file in files)
11.{
12.    FileStream stream = File.Open(file, FileMode.Open);
13.    var doc = new RadDocument();
14.    doc = provider.Import(stream);
15.    merger.AppendDocument(doc, options);
16.}
17. 
18.var editor = new RadDocumentEditor(document);
19.editor.ChangeSectionPageSize(PaperTypeConverter.ToSize(PaperTypes.A4));
20.var total = document.GetStatisticsInfo().PagesCount;
21.for(var x = 2; x <= total; x++)
22.{
23.    editor.Document.CaretPosition.MoveToPage(x);
24.    editor.InsertSectionBreak(SectionBreakType.Continuous);
25.    var section = editor.Document.Sections.ElementAt(x - 1);
26.    Padding margin;
27.    if (x % 2 == 0)
28.        margin = new Padding(50, 50, 300, 50);
29.    else
30.        margin = new Padding(300, 50, 50, 50);
31. 
32.    section.PageMargin = new Padding(margin);
33.}
34. 
35.using (Stream stream = File.OpenWrite("final.rtf"))
36.{
37.    provider.Export(editor.Document, stream);
38.}
39.Process.Start("final.rtf");
0
Tanya
Telerik team
answered on 31 Dec 2018, 09:38 AM
Hello Marcílio,

The Continuous section break creates a new section but doesn't transfer it to another page. If you would like to create the sections on different pages, you would need to use the SectionBreakType.NextPage. More information about the different types of section breaks is available in the Section help article.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Marcílio
Top achievements
Rank 1
Answers by
Martin
Telerik team
Marcílio
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or