[Python] How to remove blank page in word file using python docx or any other library...

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a word document in Docx format which has multiple blank pages. I need to delete all the blank pages in the document using python. I have tried to delete empty lines in the document. But it is not working. tried the below code:

    from docx import *
    document=Document("\\doc_path")
    z=len(document.paragraphs)
    for i in range(0,z):
    if document.paragraphs.text=="":
    document.paragraphs.clear()


    The above-mentioned code is not working and deleting all the intermediate empty lines on a page.

    Continue reading...

Compartilhe esta Página