- Import the python-docx module:
>>> import docx
- Create a new document:
>>> document = docx.Document()
- Create a paragraph that has a line break:
>>> p = document.add_paragraph('This is the start of the paragraph')>>> run = p.add_run()>>> run.add_break(docx.text.run.WD_BREAK.LINE)>>> p.add_run('And now this in a different line')>>> p.add_run(". Even if it's on the same paragraph.")
- Create a page break and write a paragraph:
>>> document.add_page_break()>>> document.add_paragraph('This appears in a new page')
- Create a new section, which will be on landscape pages:
>>> section = document.add_section( docx.enum.section.WD_SECTION.NEW_PAGE)>>> section.orientation = docx.enum.section.WD_ORIENT.LANDSCAPE>>> section.page_height, ...