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

Merge documents - apply header and footer template

5 Answers 171 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 20 Jul 2012, 11:18 PM
Hi,

Is it possible to merge documents and add a custom header / footer programmatically or via a template?

Ideally, I would like to create a header and footer template using the RadRichTextBox UI.

My application merges several documents together, where I would like to be able to apply a common header and footer style/design to them programmatically using a template that was previously designed. ** I'm only interested in the header and footer.

I know how to merge documents together, I would just like to know how I can design a Header & Footer document template and apply that design/template programmatically to the other merged documents.

Any examples that you have would be very welcome.

Thank you very much for your time,

Rob

5 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 24 Jul 2012, 01:10 PM
Hi Rob,

Yes, this is possible. You can design a document with the wanted Header and Footer and save it. Then you can apply this template to the whole document like this:

RadDocument headerAndFooterTemplate = ChooseDocument();
 
Header header = headerAndFooterTemplate.Sections.First.Headers.Default;
Footer footer = headerAndFooterTemplate.Sections.First.Footers.Default;
 
foreach (Section section in this.radRichTextBox.Document.Sections)
{
    section.Headers.Default = header;
    section.Footers.Default = footer;
}

In the example above, the ChooseDocument method returns a RadDocument which has one section with a header and footer that would be used for the merged document.

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

Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 12 Nov 2012, 05:15 PM
Petya,

Thank you for your solution. Sorry for the delay getting back to this thread, I have only just had the time to look into.
Your solution works very well, so again thank you.

There is one little problem where the footer size isn't retaining it's dimensions.
For example, when I create the template I edit the "footer from bottom" height property to about 28. However, when this is imported, the size I specified in the template isn't retained.

Do you know how I can base the document footer size on the size of the imported footer?

Thank you for your time and help.

Rob
0
Robert
Top achievements
Rank 1
answered on 12 Nov 2012, 05:39 PM
Sorry Petya,

I also need a way to auto adjust the width of the footer to compensate for landscape and portrait modes.
My document uses a mix of A4 portrait and A4 landscape sizes. You can see an example of this in the attached image. Notice how the footer in the landscape section isn't filling the whole width.

Thank you again for your time,

Rob
0
Accepted
Petya
Telerik team
answered on 13 Nov 2012, 06:05 PM
Hi Rob,

The FooterBottomMargin property is a property of Section and the logic I sent you applies the headers and footers to your merged document.. Thus, setting the property to your template document has no effect over the merged document. What you can do is specify the property when iterating through the merged document's sections:
foreach (Section section in this.radRichTextBox.Document.Sections)
{
    section.Headers.Default = header;               
    section.Footers.Default = footer;
    section.FooterBottomMargin = 23;
}

When it comes to the width of the footer - that depends on the way your template document is created. From the look of the picture you attached I tried creating a table without borders in Landscape orientation mode, which is set to auto fit to the width of the pages. Applying that document as a template successfully resized the footer.

If, however, that does not work for you, please send us more detailed explanation of your requirements, so we can help you further.
 
Kind regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 15 Nov 2012, 10:40 PM
Thanks for your response. It works well.

Here's my final solution:
RadDocument footerTemplate = Import.ImportXAML();
Footer footer = footerTemplate.Sections.First.Footers.Default;
foreach (Section section in this.radRichTextBox.Document.Sections)
{
    section.Footers.Default = footer;
    section.FooterBottomMargin = footerTemplate.Sections.First.FooterBottomMargin;
}

Thanks again,

Rob


Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Petya
Telerik team
Robert
Top achievements
Rank 1
Share this question
or