1
votes

I am creating a document using Novacode DocX. I would like the entire document to be in landscape orienation, however I would also like to have several section breaks in the document. My code is laid out like this:

DocX doc = DocX.Create(fileName);
doc.PageLayout.Orientation = Novacode.Orientation.Landscape;
foreach (string page in pages)
{
    doc.InsertSection(false);
    Paragraph p = doc.InsertParagraph();
    p.Append(page);
}

doc.PageLayout.Orientation = Novacode.Orientation.Landscape;

doc.SaveAs(Path.Combine(folderPath, fileName));

I've also tried adding doc.PageLayout.Orientation = Novacode.Orientation.Landscape inside the loop after doc.InsertSection(false) and I can't get anything past the first page to turn to landscape.

Is there a way around this?

1
I don't see a solution. It seems like there is an issue with Novacode PageLayout.Orientation after you append paragraphs larger then a page. You might be able to work around it but I need to know more of what you are trying to accomplish. - Phillip
I am creating documents with a series of section, and each section has a series of tables. Each of the tables had some title and notes around it, but there isn't any other plain text in the document. The reason I want each "chunk" of table to be in a separate section is because I want different headers for each section. If there is a way to have different headers without a separate section, that would work too. Thank you! - yammerade
Using InsertParagraphyAfterSelf() and InsertTableAfterSelf() do not affect page orientation, when extending past one page. It sounds like you are inserting paragraph text as a header, then a table, and finally another paragraph of explanation? Does this happen consistently? I think you may be able to use InsertParagraphyAfterSelf() and InsertTableAfterSelf() after last table or paragraph on page instead of Append(). You will need to know what was the last thing inserted. - Phillip
That works fine to construct the document, but it doesn't insert section breaks. I'm looking for section breaks because I want the separate sections to have different page headers. - yammerade
That is true. I tried using Microsoft.Office.Interop.Word to change orientation after using Novacode. After, each of the pages on the document are set to landscape, but they do not display as landscape(issue still exists). I don't know if you will be able to get around this with Novacode. - Phillip

1 Answers

-1
votes

See this answer from Delford Chaffin: https://stackoverflow.com/a/33178151/316578

"Creating the different sections as separate documents and inserting them into the main document worked well and solved all my problems."