Include landscaped document and linkToPrevious effect

Hi,

I have a small code that includes a document that has a portrait page with text, and then a landscaped page with text.

If I run the following code :

Document doc = new Document(); 
DocumentBuilder builder = new DocumentBuilder(doc);
// doc.getLastSection().getHeadersFooters().linkToPrevious(false);
// builder.write("my Text");
builder.insertField("INCLUDETEXT "D:\\document.doc" \\* MERGEFORMAT", "");
doc.save("C:\Temp\docIncludeFile.doc");

…I get the correct output : a portrait page and a landscaped one.

If I run this :

Document doc = new Document(); 
DocumentBuilder builder = new DocumentBuilder(doc);
doc.getLastSection().getHeadersFooters().linkToPrevious(false);
builder.insertField("INCLUDETEXT "D:\\document.doc" \\*
MERGEFORMAT", "");
doc.save("C:\Temp\docIncludeFile.doc");

I get two portrait pages.

And if I run this :

Document doc = new Document(); 
DocumentBuilder builder = new DocumentBuilder(doc);
// doc.getLastSection().getHeadersFooters().linkToPrevious(false);
builder.write("my Text");
builder.insertField("INCLUDETEXT "D:\\document.doc" \\*
MERGEFORMAT", "");
doc.save("C:\Temp\docIncludeFile.doc");

I get two portrait pages again.

Can you please explain the behavior.
I attach the file to be included.
I’m using 2.5.0 for java.

Thank you,
Milan

Hi Milan,

Thanks for your inquiry. You are right the behavior is quite odd. If section where you insert INCLUDETEXT does not contain any headers/Footers, you will get correct output. If this section contains at least header, all section inserted by INCLUDETEXT will inherit page orientation of the section. When you call doc.getLastSection().getHeadersFooters().linkToPrevious(false); it create empty headers/footers in the section and links them to the previous section.

Here are steps to reproduce the same behavior in MS Word:

  1. Create an empty document.

  2. Create header (just type some text in the header)

  3. Insert INCLUDETEXT field.

  4. Update fields in the document.

Best regards.

Hi Alexey,

What about the example where I do not call linkToPrevious, but I have some text in the document content; what happens there ?

Regards,
Milan

Hi Milan,

Thanks for your inquiry. I just tested the third scenario in MS Word and see the same behavior as with Aspose.Words. It seems if the destination section contains some content, sections included by INCLUDETEXT field inherits formatting of the destination section.

Best regards,

Yes, I’ve noticed this behavior manually in Word.
Maybe there is an option somewhere in Word to control this. I will take a deeper look.

Regards,
Milan

Hi,

Whenever you have updates regarding this behavior of Word, please put a note in here.

Thanks,
Milan

Hi Milan,

Thanks for your request. Unfortunately, I did not find anything regarding this behavior of MS Word. I suppose it would be better to contact MS word support and ask them to explain the behavior.

Best regards.