fix(docx): clean default python-docx metadata in docProps/core.xml

This commit is contained in:
bolbol committed 2026-11-10 02:46:51 +00:00
1 parent 48e8370a46
commit b0836f73a0
1 file changed
+13
+13
View File
@@ -138,6 +138,19 @@ def _execute_render_pipeline(source: dict, theme_name: str, job_id: str) -> str:
output_docx_path = os.path.join(job_dir, "output.docx") output_docx_path = os.path.join(job_dir, "output.docx")
try: try:
docx_meta = renderer_docx.render_docx(source, theme_tokens, output_docx_path, figures_map, pdf_text=pdf_text) docx_meta = renderer_docx.render_docx(source, theme_tokens, output_docx_path, figures_map, pdf_text=pdf_text)
try:
import zipfile, io
with open(output_docx_path, "rb") as _f: _raw = _f.read()
_zin = zipfile.ZipFile(io.BytesIO(_raw), "r"); _zbuf = io.BytesIO()
_zout = zipfile.ZipFile(_zbuf, "w", compression=zipfile.ZIP_DEFLATED)
for _item in _zin.infolist():
_b = _zin.read(_item.filename)
if _item.filename == "docProps/core.xml":
_b = _b.replace(b"generated by python-docx", b"series-studio")
_zout.writestr(_item, _b)
_zin.close(); _zout.close()
with open(output_docx_path, "wb") as _f: _f.write(_zbuf.getvalue())
except Exception: pass
journal_lines.append(f"DOCX rendu avec succès : {docx_meta['omath']} formules OMML, {docx_meta['draw']} figures, {docx_meta['dollar']} dollar(s)") journal_lines.append(f"DOCX rendu avec succès : {docx_meta['omath']} formules OMML, {docx_meta['draw']} figures, {docx_meta['dollar']} dollar(s)")
except Exception as e: except Exception as e:
journal_lines.append(f"ERREUR rendu DOCX : {e}") journal_lines.append(f"ERREUR rendu DOCX : {e}")