You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using docx to open a template and add some content as a first page. I then want to use a different template for subsequent pages (different watermarks). I then want to save all pages in one document. Is this possible in python-docx?
Inspired by this comment #182 (comment) the following code works for me:
document = Document('MainTemplate.docx')
# add content
last_part_file = os.path.join('LastPart.docx')
last_part_doc = Document(last_part_file)
for para in last_part_doc.paragraphs:
document._body._body._insert_p(para._p)
The content from LastPart.docx gets appended at the end of the new Document. The formatting looks like in the original LastPart.docx. (There are no bullet point lists but numbered lists, and they come out fine.)
I'm using docx to open a template and add some content as a first page. I then want to use a different template for subsequent pages (different watermarks). I then want to save all pages in one document. Is this possible in python-docx?
this is how I'm creating my document
I'm wondering if I can add
other_pages.render(context)
out_2 = StringIO()
other_pages.save(out_2)
and then something like
payload = out.getvalue() + out_2.getvalue()
This creates a file but when I try to open it I get the message "this file is corrupt and cannot be opened"
The text was updated successfully, but these errors were encountered: