简体   繁体   中英

Python docx page break

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM