1

When you write something in docx file and you are at the end of the page Microsoft world automatically render you to a new blank page . is there any way you can know with python docx if you are in the new page.

GED98
  • 11
  • 1
  • have you checked in documentation? breaks should be available in runs in docx, see https://python-docx.readthedocs.io/en/latest/dev/analysis/features/text/breaks.html – Maciej Wrobel Jan 28 '22 at 13:55

2 Answers2

1

There is 2 types of page breaks in word documents, soft and hard. Soft break are not not detectable and hard page break.

Here is a good post about it https://stackoverflow.com/questions/53084249/python-docx-identify-a-page-break-in-paragraph#:~:text=There%20is%20no%20way%20to%20detect%20soft%20page,you%27ll%20find%20a%20more%20elaborate%20explanation%20of%20this.

  • This answer could probably be a comment, unless you cite the specific parts of the cited source that are relevant to the question (AND provide an attempt to answer the question) – aaossa Mar 04 '22 at 20:12
  • Thanks for linking to the other SO question, Laurent. That question's accepted answer suggests that soft breaks are actually detectable, so I've submitted another answer based on your link. Cheers! – Esteis Mar 08 '22 at 13:44
0

As I understand it, a docx paragraph consists of runs, and some of those runs are or contain a page break. (I don't know the data model, so I don't know whether 'some runs are' or 'some runs contain' is correct.)

This other answer on Stack Overflow says that it is possible to detect whether a run is/contains a soft page break.

Hopefully you can use that to determine whether your text is before or after the soft page break. I hope this helps.

Esteis
  • 4,669
  • 2
  • 29
  • 45
  • Just a note to the person who just edited this question: the SO guideline for removing polite phrases is ["Remove 'Hi' and 'Thank you' - but only while you're at it."](https://meta.stackoverflow.com/a/303220/473899). I don't mind you removing it. I hope you don't mind me putting it back. – Esteis Mar 08 '22 at 13:58