-1

I want to put an image on the top of the first page of the document so I pit on header now it's appearing on the rest of the pages would anyone propose another solution or how adapt it so it won't appear on the rest if the pages I am using docx on python

I tried first_page_header and linked_to_previous properties but no results

    doc = docx.Document()
    doc.sections[0].header.paragraphs[0].paragraph_format.left_indent = -Inches(1.25)
    doc.sections[0].header_distance = Pt(0)
    doc.sections[0].different_first_page_header_footer = True
    doc.sections[0].header.is_linked_to_previous = False
    doc.sections[0].header.paragraphs[0].add_run().add_picture("./image/french_header.png")

it removes header from the first page and make still on the rest of the pages I want the opposite

Albina
  • 1,901
  • 3
  • 7
  • 19
  • is this link helpful for you ? https://stackoverflow.com/questions/55709175/how-to-add-a-logo-on-the-top-left-of-ms-word-document-using-the-python-docx-libr – inkredusk Apr 16 '23 at 11:26

1 Answers1

0

i just used add_piture instead of working with header here's the new version of my code

    doc = docx.Document()
    p = doc.add_paragraph()
    r = p.add_run()
    r.add_picture('./image/french_header.png')
    p.paragraph_format.left_indent = -Inches(1.25)
    # Set the top margin of the first paragraph to zero
    doc.sections[0].top_margin = docx.shared.Pt(0)