44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
import xml.etree.ElementTree as ET
|
|
|
|
from docx import Document
|
|
|
|
from lxml import etree
|
|
|
|
def find_default_font(expected, config_file_path):
|
|
"""Find the default font in LibreOffice Writer."""
|
|
default_font = None
|
|
try:
|
|
tree = ET.parse(config_file_path)
|
|
root = tree.getroot()
|
|
|
|
# Define the XML namespace used in the file
|
|
namespace = {'oor': 'http://openoffice.org/2001/registry'}
|
|
|
|
# Search for the node containing the default font setting for LibreOffice Writer
|
|
for elem in root.findall('.//item[@oor:path="/org.openoffice.Office.Writer/DefaultFont"]', namespace):
|
|
for prop in elem.findall('.//prop[@oor:name="Standard"]', namespace):
|
|
for value in prop.findall('value', namespace):
|
|
default_font = value.text
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
return 1 if default_font == expected else 0
|
|
|
|
|
|
def contains_page_break(docx_file):
|
|
doc = Document(docx_file)
|
|
|
|
namespaces = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'}
|
|
|
|
for paragraph in doc.paragraphs:
|
|
for run in paragraph.runs:
|
|
br_elems = run.element.findall('.//w:br', namespaces)
|
|
for br in br_elems:
|
|
if br is not None and '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type' in br.attrib and br.attrib['{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type'] == 'page':
|
|
return 1
|
|
return 0
|
|
# Replace 'your_document.docx' with the path to your document
|
|
# result = contains_page_break('your_document.docx')
|
|
# print(result)
|
|
|
|
#config_path = "/home/[username]/.config/libreoffice/4/user/registrymodifications.xcu"
|
|
#print(find_default_font("Ani", config_path)) |