Commit 9484b88b authored by Ingo Meyer's avatar Ingo Meyer

Use `qpdf` to optimize / repair produced PDF files from `rsvg-convert`

parent 8d9f884d
......@@ -19,6 +19,7 @@ from .output_mode import get_output_mode
TMP_IMAGE_FILENAME = "_downloaded_image{i:04d}.{ext}"
TMP_QPDF_OUT_FILENAME = "_qpdf_out.pdf"
OUT_PDF_FILENAME = "_converted_image{i:04d}.pdf"
......@@ -65,6 +66,14 @@ def load_and_convert_image(image_filepath_or_url, convert_to_base64=True, conver
stdout=devnull,
stderr=devnull,
)
try:
subprocess.check_call(
["qpdf", out_pdf_filename, TMP_QPDF_OUT_FILENAME], stdout=devnull, stderr=devnull
)
os.remove(out_pdf_filename)
shutil.move(TMP_QPDF_OUT_FILENAME, out_pdf_filename)
except subprocess.CalledProcessError:
pass
image_filepath = out_pdf_filename
image_is_svg = False
image_is_pdf = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment