Skip to content
Snippets Groups Projects
Commit 3a643710 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding pure python emf to png converter

parent f46a2a97
Branches
No related tags found
No related merge requests found
......@@ -20,3 +20,4 @@ rich==13.7.0
# via oneM2M-spec-2-MD-converter (setup.py)
typing-extensions==4.8.0
# via python-docx
pillow==10.1.0
......@@ -26,6 +26,8 @@ from rich import inspect
import configparser, zipfile
from lxml import etree as ET
from PIL import Image
class Style(IntEnum):
example = auto()
image = auto()
......@@ -620,6 +622,7 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
elif style in docConfig.tablecaption:
lines.append('')
caption = replaceNL(text).strip()
caption = replaceNL(text).strip()
anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else ''
lines.append(f'**{caption}**{anchor}')
......@@ -824,10 +827,12 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
cmd = converter
cmd = cmd.replace('{infile}', fn).replace('{outdir}', _t)
_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
_print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
break
convert(fn, fn[:-4])
#if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
# _print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
# _print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
# break
if not skipImageConversion:
if docConfig.emfConverterPng:
......@@ -842,6 +847,10 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
progress.stop()
def convert(input:str, output_name:str):
name=output_name+".png"
Image.open(input).save(str(name))
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment