Skip to content

Commit

Permalink
POC which generate pdf file from docx locally using libreoffice
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Feb 5, 2024
1 parent 1810c85 commit 6da5842
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions conventions/services/convention_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import math
import os
import subprocess

import convertapi
import jinja2
Expand Down Expand Up @@ -304,9 +305,22 @@ def generate_pdf(file_stream: io.BytesIO, convention: Convention):
os.remove(local_docx_path)
else:
convention_dirpath = f"conventions/{convention.uuid}/convention_docs"
convention_filename = f"{convention.uuid}.docx"
pdf_path = _save_io_as_file(
file_stream, convention_dirpath, convention_filename
convention_docx_filename = f"{convention.uuid}.docx"
convention_pdf_filename = f"{convention.uuid}.pdf"
doc_path = _save_io_as_file(
file_stream, convention_dirpath, convention_docx_filename
)
pdf_path = f"{convention_dirpath}/{convention_pdf_filename}"
subprocess.run(
[
"/Applications/LibreOffice.app/Contents/MacOS/soffice",
"--convert-to",
"pdf:writer_pdf_Export",
"--outdir",
f"media/{convention_dirpath}",
f"media/{doc_path}",
],
check=True,
)

file_stream.seek(0)
Expand Down

0 comments on commit 6da5842

Please sign in to comment.