Пример кода:
Код: Выделить всё
from docx import Document
from pathlib import Path
if __name__ == "__main__":
tmp_path = Path("../data")
docx_path = tmp_path / "long_docx_with_breaks.docx"
document = Document()
for i in range(10):
document.add_paragraph(f"This is paragraph {i + 1}.\n\n")
if i % 2 == 1: # Add a page break every 2 paragraphs
document.add_page_break()
document.save(docx_path)
check_doc = Document(docx_path)
for paragraph in check_doc.paragraphs:
if paragraph.contains_page_break:
print("page_break")
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-document
Мобильная версия