[Python] Python: issue using WD_ALIGN_PARAGRAPH.RIGHT with photo

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    When using the titular command with an image after using "add_run", the image is not right aligned. I was attempting to recreate something similar to this but swapping the picture and text section. Unsure if this can be achieved with the library.

    from docx import Document
    from docx2pdf import convert
    from docx.enum.text import WD_ALIGN_PARAGRAPH
    from docx.shared import Inches, RGBColor, Pt

    header = doc1.sections[0].header
    htable = header.add_table(1,2,Inches(9))
    htab_cells = htable.rows[0].cells
    ht0=htab_cells[1].add_paragraph()
    kh=ht0.add_run()
    kh.add_picture(holder_logo,width=Inches(.75))
    kh.alignment = WD_ALIGN_PARAGRAPH.RIGHT
    header1=htab_cells[0].add_paragraph().add_run("Notice to Zero Dollar Change\nDATA CENTER")
    header1.font.size = Pt(16)
    header1.font.name = 'AvantGarde LT Book'
    header1.font.color.rgb = RGBColor.from_string("0266BB")

    Continue reading...

Compartilhe esta Página