How to remove blank page in word file using python docx or any other library available in python?

Viewed 148

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[i].text=="":
        document.paragraphs[i].clear()

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

0 Answers
Related