Merge documents - apply header and footer template

6 posts, 1 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 20 Jul 2012 Link to this post

    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
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 24 Jul 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 12 Nov 2012 Link to this post

    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
  5. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 12 Nov 2012 Link to this post

    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
  6. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 13 Nov 2012 Link to this post

    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.

  7. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 15 Nov 2012 Link to this post

    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


Back to Top
UI for WPF is Visual Studio 2017 Ready