I already have the solution
1. I create the main document, the first page in the first section, I set the orientation as I want and I add new next section.
2. I read LinkedDocument file to rtf file, then rtf to another doc. Next I read each sections (by .Copy ()), I read its PageSetup.Orientation, I add a paragraph into the main document, I set PageSetup.Orientation main document to be compatible with the document (doc with LinkedDocument), I add it into the main document (.PasteAndFormat ()).
3. At the end I delete doc file with LinkedDocument
and it looks like ...
dokMD = word.Documents.Add(<template.dot>, ...)
secDokMDFirst = dokMD.Sections.First;
secDokMDFirst.Range.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
EA.IDualElement el = Repository.GetElementByID(kl.ElementID);
string linkedDocument = el.GetLinkedDocument();
if (linkedDocument.Length > 0)
{
String myXMLfileName = System.IO.Path.GetTempFileName() + ".rtf";
using (StreamWriter outfile = new StreamWriter(myXMLfileName))
outfile.Write(linkedDocument);
WdOrientation docLDPSO = WdOrientation.wdOrientPortrait;
object missing = Missing.Value;
object dokFormat = WdOpenFormat.wdOpenFormatRTF;
Word._Document docLD = word.Documents.Open(myXMLfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref dokFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
if (docLD.Words.Count > 0)
{
docLD.SaveAs(myXMLfileName, WdSaveFormat.wdFormatRTF);
}
dokMD.Sections.Add();
int idx = 0;
foreach (Section secdocLD in docLD.Sections)
{
secdocLD.Range.Copy();
idx = secdocLD.Index;
docLDPSO = secdocLD.PageSetup.Orientation;
dokMD.Activate();
dokMD.Paragraphs.Add();
par = dokMD.Paragraphs.Last;
secDokMDLast = dokMD.Sections.Last;
secDokMDLast.PageSetup.Orientation = docLDPSO;
par.Range.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
}
docLD.Close(false);
System.IO.File.Delete(myXMLfileName);
Marshal.FinalReleaseComObject(docLD);
}