0

I'm using Novacode DocX to generate a Word (DocX) document in C#. At some point in the code, I have a reference to a paragraph object, and I'd like to know what page that paragraph is on. Unfortunately, there is no Pargraph.PageNumber option, or anything of the sort.

Is there a workaround for this?

Wouter
  • 100
  • 1
  • 7
  • I don't think it would be possible, since the paging information is not included inside the docx document, it can only be computed if you render the docx, and I don't think Novacode knows how to render docx. – edi9999 Feb 10 '17 at 08:40
  • I see what you mean, thanks for your response. Now I came up with a way to simulate the same behaviour, using a Table of Contents (since that uses placeholders for page numbers). However, when I edit the document, the ToC isn't automatically updated. Do you know if it's possible to use Novacode DocX to force update the ToC, or generate a new one, with only a specific header level? – Wouter Feb 17 '17 at 10:16

1 Answers1

0

To generate a table of content you can use this code :

DocX myDocument = DocX.Load(FilePath);

TableOfContents ToC = fullReportDocument.InsertTableOfContents(
        title : "Your Title",
        switches : TableOfContentsSwitches.O | TableOfContentsSwitches.H | TableOfContentsSwitches.Z | TableOfContentsSwitches.U,
        headerStyle : null,
        maxIncludeLevel : 2
);

maxIncludeLevel is probably the parameter you want

G.Dealmeida
  • 325
  • 3
  • 14