from docx import Document from docx.enum.text import WD_BREAK
def duplicate_second_page_content(doc, num_days): # Get the content of the second page second_page = doc.sections[1].header content = [paragraph.text for paragraph in second_page.paragraphs]
# Iterate through the remaining pages and duplicate the content
for i in range(1, num_days):
if len(doc.sections) <= i:
# If the document has fewer sections than expected, add a new section
doc.add_section()
# Get the header of the current section
current_header = doc.sections[i].header
# Add paragraphs with the content from the second page
for text in content:
current_header.add_paragraph(text)
return doc
Load the Word document
doc = Document('final_template.docx')
Define the number of days
num_days = 5 # Change this to the desired number of days
Duplicate the content and add page breaks
doc = duplicate_second_page_content(doc, num_days)
Save the modified document
doc.save('modified_document.docx')
i wanted to create duplicate of an page in my template