TransWikia.com

How can I remove the space between paragraphs using python-docx?

Stack Overflow Asked by Mario Tunon on January 12, 2021

I am trying to make a simple script to create a .docx document.
I am using the python-docx library in a windowed environment of python 3.7.

When I add a .png in the header of my word and then add another paragraph. I see in the word a space between one paragraph and the other.
I’d like to see if you could help me figure out how I can eliminate this. Below this is the code I have and the image of the space.

from docx import Document
from docx.shared import Inches, Pt
import os, datetime

doc = Document("plantilla.docx")
coreprops = doc.core_properties
props = dir(coreprops)
coreprops.author = "Osiris Quintero"
coreprops.comments = "Este archivo documenta las instalaciones de cliente por radio enlace"
coreprops.revision = 2
coreprops.created = datetime.datetime.now()

style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(14)

direction = r'C:UsersMats_Pictureslogo.png'
header = doc.sections[0].header
paragraph = header.paragraphs[0]
logo_run = paragraph.add_run()
logo_run.add_picture(direction, width=Inches(1.85))

titule = doc.add_paragraph()
titule_1 = titule.add_run()
titule_1.add_text("test")

doc.save('path_to_document.docx')
os.startfile(r'D:proyectos de pythoncrear_archivo_de_word_para_osirispath_to_document.docx')

Output:
current output

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP