Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit bd7b7d7

Browse files
committed
Add/Improve docstrings on backends
1 parent 62345c9 commit bd7b7d7

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

camelot/backends/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""pypdf_table_extraction offers multiple backends to convert the PDFs to images so it can be analyzed by opencv."""
2+
13
from .image_conversion import ImageConversionBackend

camelot/backends/ghostscript_backend.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
"""Creates a ghostscript backend class to convert a pdf to a png file."""
2+
3+
14
class GhostscriptBackend:
5+
"""Classmethod to create GhostscriptScriptBackend."""
26

37
def convert(self, pdf_path, png_path, resolution=300):
8+
"""Convert a PDF to a PNG image using Ghostscript .
9+
10+
Parameters
11+
----------
12+
pdf_path : str
13+
[description]
14+
png_path : str
15+
[description]
16+
resolution : int, optional
17+
[description], by default 300
18+
19+
Raises
20+
------
21+
OSError
22+
[description]
23+
"""
424
try:
525
import ghostscript
626
except RuntimeError:

camelot/backends/image_conversion.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Classes tand functions for the ImageConversionBackend backends."""
2+
13
from .ghostscript_backend import GhostscriptBackend
24
from .poppler_backend import PopplerBackend
35

@@ -6,7 +8,23 @@
68

79

810
class ImageConversionBackend:
11+
"""Classes the ImageConversionBackend backend."""
12+
913
def __init__(self, backend="poppler", use_fallback=True):
14+
"""Initialize the conversion backend .
15+
16+
Parameters
17+
----------
18+
backend : str, optional
19+
[description], by default "poppler"
20+
use_fallback : bool, optional
21+
[description], by default True
22+
23+
Raises
24+
------
25+
ValueError
26+
[description]
27+
"""
1028
if backend not in BACKENDS.keys():
1129
raise ValueError(f"Image conversion backend '{backend}' not supported")
1230

@@ -15,6 +33,22 @@ def __init__(self, backend="poppler", use_fallback=True):
1533
self.fallbacks = list(filter(lambda x: x != backend, BACKENDS.keys()))
1634

1735
def convert(self, pdf_path, png_path):
36+
"""Convert PDF to png_path.
37+
38+
Parameters
39+
----------
40+
pdf_path : str
41+
Path where to read the pdf file.
42+
png_path : str
43+
Path where to save png file.
44+
45+
Raises
46+
------
47+
type
48+
[description]
49+
type
50+
[description]
51+
"""
1852
try:
1953
converter = BACKENDS[self.backend]()
2054
converter.convert(pdf_path, png_path)

camelot/backends/poppler_backend.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""Creates a poppler backend class to convert a pdf to a png file.
2+
3+
Raises
4+
------
5+
OSError
6+
[description]
7+
ValueError
8+
[description]
9+
"""
10+
111
import os
212
import shutil
313
import subprocess
@@ -8,7 +18,25 @@
818

919

1020
class PopplerBackend:
21+
"""Classmethod to create a poplerBackendBackend class."""
22+
1123
def convert(self, pdf_path, png_path):
24+
"""Convert PDF to png.
25+
26+
Parameters
27+
----------
28+
pdf_path : str
29+
Path where to read the pdf file.
30+
png_path : str
31+
Path where to save png file.
32+
33+
Raises
34+
------
35+
OSError
36+
[description]
37+
ValueError
38+
[description]
39+
"""
1240
pdftopng_executable = shutil.which("pdftopng", path=path)
1341
if pdftopng_executable is None:
1442
raise OSError(

0 commit comments

Comments
 (0)