There are many problems in your document:
- it is a .docx one, i.e. it is not Writer native format and all advices which could be given are stable and valid only for .odt
- it is exclusively direct formatted, i.e. it does not use the high-level formatting features called styles which disconnect contents from appearance (for your defence, M$ Word is rather poor on this matter because it only offers paragraph styles)
Oh, yes, you structured your headings with Heading n styles but this is only a very minor aspect of the general problem.
- sending TOC page number into the margin is a Word specificity which does not exist in Writer
To be rigorous, this is not what you’ve done. In your document, you modified the indents of the TOC paragraph styles. So, technically, your page number are not “in the margins”; they are inside the paragraph bounding box. Consequently, they should display “normally” in the PDF.
Globally, your document structure has been damaged beyond repair by the cumulative conversions to/from DOCX.
Your formatting is inconsistent. You should try and look for some clipping between your user-defined page size and PDF destination page. In such a long book, it is mandatory to follow a strict formatting method based on styles and to refrain from using direct formatting. The commonly agreed threshold between direct formatting and styling is around 5 pages!