Python-docx go to next page once a word is detected

I have a text file where i am reading my text from somthing like this

test.txt

the quick brown fox End of Doc what is the meaning of life and earch End of Doc ... 

So I read this into a varible then I pass it over to python docx to create a word document What I need to do is where ever it says End of Doc I need to go to the next page this is what I have so far

import docx from docx.enum.text import WD_BREAK     def readFile():         f = open("test.txt", "r")         return f.read()          def makeDocx():          txt = readFile()         doc = docx.Document()         p = doc.add_paragraph(txt)          doc.save('test.docx')          makeDocx() 

I have tried this but does not seem to work

def makeDocx():           txt = readFile()     doc = docx.Document()     p = doc.add_paragraph(txt)     for paragraph in doc.paragraphs:         if 'End of Doc' in paragraph.text:             run = paragraph.add_run()             run.add_break(WD_BREAK.PAGE)     doc.save('test.docx') 

but it does not seem to go to the next page

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.