Skip to content

Commit

Permalink
Add pdf2image backend
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenkmurray committed Sep 8, 2022
1 parent 644bbe7 commit 2c40bae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion camelot/backends/image_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from .poppler_backend import PopplerBackend
from .ghostscript_backend import GhostscriptBackend
from .pdf2image_backend import PDF2ImageBackend

BACKENDS = {"poppler": PopplerBackend, "ghostscript": GhostscriptBackend}
BACKENDS = {"pdf2image": PDF2ImageBackend, "poppler": PopplerBackend, "ghostscript": GhostscriptBackend}


class ImageConversionBackend(object):
Expand Down
17 changes: 17 additions & 0 deletions camelot/backends/pdf2image_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

import os
import shutil
import subprocess
from pdf2image import convert_from_path

class PDF2ImageBackend(object):
def convert(self, pdf_path, png_path):

try:
output_folder = os.path.dirname(png_path)
output_file = os.path.splitext(os.path.basename(png_path))[0]
paths = convert_from_path(pdf_path, output_folder=output_folder, output_file=output_file, dpi=300, fmt='png',
single_file=True, use_pdftocairo=True, paths_only=True)
except subprocess.CalledProcessError as e:
raise ValueError(e.output)
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


requires = [
"chardet>=3.0.4",
"click>=6.7",
"numpy>=1.13.3",
"openpyxl>=2.5.8",
Expand All @@ -24,7 +23,7 @@
"tabulate>=0.8.9",
]

base_requires = ["ghostscript>=0.7", "opencv-python>=3.4.2.17", "pdftopng>=0.2.3"]
base_requires = ["opencv-python>=3.4.2.17", "pdftopng>=0.2.3"]

plot_requires = [
"matplotlib>=2.2.3",
Expand Down

0 comments on commit 2c40bae

Please sign in to comment.