1

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?

yammerade
  • 629
  • 8
  • 20
  • 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 Oct 07 '15 at 21:40
  • 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 Oct 08 '15 at 13:28
  • 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 Oct 08 '15 at 16:38
  • 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 Oct 09 '15 at 01:25
  • 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 Oct 09 '15 at 12:57
  • Unfortunate :-( Thanks for your help! – yammerade Oct 09 '15 at 20:40
  • @LisaMcCusker ... Did you ever get anywhere with this? I'm having tons of issues with sections, headers/footers and orientation as well. – Delford Chaffin Oct 16 '15 at 16:00
  • Nope. I just did away with the sections idea. Sorry! Good luck! – yammerade Oct 16 '15 at 21:23

1 Answers1

-1

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."

Anthony Hayward
  • 2,164
  • 21
  • 17