add eval libreoffice writer compare image & centering & check file existence
This commit is contained in:
@@ -146,6 +146,30 @@ def has_page_numbers_in_footers(docx_file):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
||||
|
||||
def is_first_line_centered(docx_file):
|
||||
doc = Document(docx_file)
|
||||
first_paragraph = doc.paragraphs[0]
|
||||
|
||||
# check if the first line is center justified
|
||||
return 1 if first_paragraph.paragraph_format.alignment == WD_PARAGRAPH_ALIGNMENT.CENTER else 0
|
||||
|
||||
import os
|
||||
def check_file_exists(directory, filename):
|
||||
|
||||
file_path = os.path.join(directory, filename)
|
||||
return 1 if os.path.isfile(file_path) else 0
|
||||
|
||||
def compare_contains_image(docx_file1, docx_file2):
|
||||
doc1 = Document(docx_file1)
|
||||
doc2 = Document(docx_file2)
|
||||
|
||||
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
|
||||
for run1, run2 in zip(para1.runs, para2.runs):
|
||||
if ('graphicData' in run1._element.xml and 'graphicData' not in run2._element.xml) or ('graphicData' not in run1._element.xml and 'graphicData' in run2._element.xml):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
# file1 = 'path/to/file1.docx'
|
||||
# file2 = 'path/to/file2.docx'
|
||||
|
||||
Reference in New Issue
Block a user