We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to avoid section break with ImportContent method

Thread ID:

Created:

Updated:

Platform:

Replies:

138493 Jul 3,2018 10:26 AM UTC Jul 17,2018 12:42 PM UTC WinForms 8
loading
Tags: DocIO
Florider
Asked On July 4, 2018 08:20 AM UTC

Hello,

I tried to insert a sub word document into a main word document using your ImportContent method.
But each time i call this method i get a new section and the header / footer of the new section is not linked to the previous section.
I already set the BreakCode property of the sub template to NoBreak to avoid empty pages, but section breaks are still there.
I need to preserve the same header / footer on every inserted page. So, before searching for inserted sections and playing with LinkToPrevious property on each new section, i'd like to know if there's a way to avoid section breaks.

Best regards,

Flo



Dilli Babu Nandha Gopal [Syncfusion]
Replied On July 5, 2018 01:58 PM UTC

Hi Flo, 
 
Thank you for contacting Syncfusion supports. 
 
From the given details, we suspect that your requirement is to merge the two Word documents (sub and main Word document) and to start the contents of sub document in same page with main document’s header and footer. We have prepared a sample application to merge sub Word document at the end of main Word document and to preserve header and footers from the main Word document. 
 
Please find the sample from the below link: 
Note: Please find the input documents in “Data” folder of above sample application. 
 
In this sample, we have done the following things: 
  1. Loads a main Word document using DocIO. 
  2. Loads a sub Word document. 
  3. Set page settings from main Word document to sub Word document. 
  4. Removes headers and footers of sub Word document. 
  5. Imports the contents of sub Word document into main Word document. 
  6. Saves the main Word document. 
 
Could you please provide us your confirmation on whether the contents of sub Word document to start in new page or in same page after the end of main document content ? so that we can modify the sample accordingly. 
 
If the above sample doesn’t work with your input documents, kindly provide us the input Word documents (with dummy data) and the expected output document. Thereby, we will analyze the feasibility to achieve your requirement using DocIO and provide you the appropriate solution at the earliest. 
 
Regards, 
Dilli babu. 


Florider
Replied On July 6, 2018 04:55 PM UTC

Hello,

First of all, thank you very much for your detailed answer.
Your sample works very well with your templates, but not with mines (attached into the answer).
My templates are .doc files (not docx) and the main document is configurated with a different header on the first page (HEADER1). The rest of the document use another hearder (HEADER 2).
When i use your sample, i see HEADER1 on the first page of the inserted sub document.
The created section is well attached to the previous section, but Word shows the wrong header.

I notice in your code that you change the DifferentFirstPage property of the sub template before inserting it.
I don't know if it's an important / useful step (is it ?) but if remove it, then your sample works with my templates (HEADER2 appears).
So, i guess there's maybe something wrong with my templates configuration, but what ?
I could change the code and go ahead without thinking, but i'd like to understand.

Thanks again for your help.

Best regards,

Flo



Attachment: Data_a53b43ba.zip

Dilli Babu Nandha Gopal [Syncfusion]
Replied On July 10, 2018 05:34 AM UTC

Hi Flo, 

Thank you for your patience. 

In Microsoft Word documents there are 3 types of header footers,  
First page header footer  
If DifferentFirstPage property of a section is true, first page header footer is visible for the first page of that section.  
Even page header footer  
If DifferentOddAndEvenPages property of document is true and DifferentFirstPage property is false, even page header footer is visible for the even numbered pages of document. 
If DifferentFirstPage property of a section is true, first page header footer is visible for the first page of that section alone instead of even page header footer. 
Odd page header footer (default)  
If DifferentOddAndEvenPages property of document is true and DifferentFirstPage property is false, odd page header footer is visible for the odd numbered pages of document. 
If DifferentOddAndEvenPages property of document is false and DifferentFirstPage property is false, odd page header footer is visible for all the pages of document (Since it is default header footer). 
If DifferentFirstPage property of a section is true, first page header footer is visible for the first page of that section alone instead of odd page header footer. 
Note:   
DifferentOddAndEvenPages property is common to all sections in a document. 
DifferentFirstPage property is unique for each section in a document. 
  
There is nothing wrong in your templates, you have set DifferentFirstPage property to true in the main document that too for your requirement.  
  
In our previous sample, we have added the highlighted code to copy the last section DifferentFirstPage property value of main document to all the sections of sub document. Whereas this copying of DifferentFirstPage property value is not necessary for your requirement, so you can remove the highlighted codes and proceed with our previous sample.  
//Opens the main document   
WordDocument mainDocument = new WordDocument(targetFileName);  
  
//Get page setup from main document.  
bool isDifferentFirstPage = mainDocument.LastSection.PageSetup.DifferentFirstPage;  
WPageSetup pageSetup = mainDocument.LastSection.PageSetup;  
  
//Opens the sub document   
WordDocument subDocument = new WordDocument(sourceFileName);  
  
//Iterate each section in sub Word document.  
foreach (WSection section in subDocument.Sections)  
{  
    //Set page settings as per the destination document.  
    section.PageSetup.Margins = pageSetup.Margins;  
    section.PageSetup.Orientation = pageSetup.Orientation;  
    section.PageSetup.PageSize = pageSetup.PageSize;  
    section.PageSetup.DifferentFirstPage = isDifferentFirstPage;  
    section.PageSetup.HeaderDistance = pageSetup.HeaderDistance;  
    section.PageSetup.FooterDistance = pageSetup.FooterDistance;  
    section.HeadersFooters.LinkToPrevious = true;  
  
    //Clears header and footers from source document.  
    section.HeadersFooters.OddHeader.ChildEntities.Clear();  
    section.HeadersFooters.EvenHeader.ChildEntities.Clear();  
    section.HeadersFooters.FirstPageHeader.ChildEntities.Clear();  
    section.HeadersFooters.OddFooter.ChildEntities.Clear();  
    section.HeadersFooters.EvenFooter.ChildEntities.Clear();  
    section.HeadersFooters.FirstPageFooter.ChildEntities.Clear();  
}  
  
Please let us know if you have any other questions.  

Regards, 
Dilli babu. 


Florider
Replied On July 11, 2018 01:12 PM UTC

Hello,

Thanks for your answer. 
Tell me if i 'm wrong but your main template is also configured with DifferentFirstPage property to true and your sample works with the highlighted code (each section keeps the second header / footer of the main document)
So i guess there's a difference between your templates' configuration and mine, but what ?

Best regards, 

Flo



Dilli Babu Nandha Gopal [Syncfusion]
Replied On July 12, 2018 07:38 AM UTC

Hi Flo, 

On further analyzing with your inputs, the only difference is section break of first section in the sub documents. In your sub document, section break is not defined in the file level and considered as new page (default). So, the merged contents are started from a new page, which makes different first page header footer to be visible. 

Whereas in our sub document, continuous section break is already defined in the file level. So, the merged contents are continued in same page from the end of main Word document, which makes different first page header footer not visible.  

Since, there is no independent first page for merged sub document’s first section (It shares the last page of main document), different first page header footer is not visible.  

This is the Microsoft Word behavior based on section break type and DifferentFirstPage property. We hope it now clear to you. 

Please let us know if you have any questions. 

Regards, 
Dilli babu. 


Florider
Replied On July 13, 2018 07:28 AM UTC

Hello,

I understand the behavior your describe, but i'm not able to see the continuous section break into your sub document.
You say : "continuous section break is already defined in the file level". But how to see it  in MS Word ?

Best regards,

Flo

Dilli Babu Nandha Gopal [Syncfusion]
Replied On July 13, 2018 10:02 AM UTC

Hi Flo, 

To view section break type in the current section of Word document using Microsoft Word application, go to Layout menu -> expand Page Setup dialog -> go to Layout tab as per the below screenshot: 

 

 
Please let us know if you need any further assistance on this. 
 
Regards, 
Dilli babu. 


Florider
Replied On July 17, 2018 12:42 PM UTC

Hello,

Everything is clear now. Thank you very much for your assistance !

Best regards,

Flo

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon