From 96b9f04e387ae882c70ffbeab1931e24c0729031 Mon Sep 17 00:00:00 2001 From: orent Date: Thu, 30 Sep 2021 14:10:30 +0300 Subject: [PATCH] Call pdftopng in python instead of subprocess Using the poppler backed failed for me because I was running it from an un-activated venv and pdftopng was not in the PATH. My original workaround was even shorter - I imported the convert function directly into the PopplerBackend class. But this import will fail on initialization if pdftopng is not installed and will prevent using the ghostscript backend, so I converted it to late import. --- camelot/backends/poppler_backend.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/camelot/backends/poppler_backend.py b/camelot/backends/poppler_backend.py index 4103372..eeaae9f 100644 --- a/camelot/backends/poppler_backend.py +++ b/camelot/backends/poppler_backend.py @@ -6,17 +6,5 @@ import subprocess class PopplerBackend(object): def convert(self, pdf_path, png_path): - pdftopng_executable = shutil.which("pdftopng") - if pdftopng_executable is None: - raise OSError( - "pdftopng is not installed. You can install it using the 'pip install pdftopng' command." - ) - - pdftopng_command = [pdftopng_executable, pdf_path, png_path] - - try: - subprocess.check_output( - " ".join(pdftopng_command), stderr=subprocess.STDOUT, shell=True - ) - except subprocess.CalledProcessError as e: - raise ValueError(e.output) + from pdftopng.pdftopng import convert + convert(pdf_path, png_path)