diff --git a/camelot/core.py b/camelot/core.py index 3813e60..a7f8d78 100644 --- a/camelot/core.py +++ b/camelot/core.py @@ -333,7 +333,8 @@ class Table(object): """ if self.flavor == 'stream' and geometry_type in ['contour', 'joint', 'line']: - raise NotImplementedError("{} cannot be plotted with flavor='stream'") + raise NotImplementedError("{} cannot be plotted with flavor='stream'".format( + geometry_type)) if geometry_type == 'text': plot_text(self._text) @@ -444,13 +445,25 @@ class TableList(object): def __getitem__(self, idx): return self._tables[idx] + def __iter__(self): + self._n = 0 + return self + + def next(self): + if self._n < len(self): + r = self._tables[self._n] + self._n += 1 + return r + else: + raise StopIteration + @staticmethod def _format_func(table, f): return getattr(table, 'to_{}'.format(f)) @property def n(self): - return len(self._tables) + return len(self) def _write_file(self, f=None, **kwargs): dirname = kwargs.get('dirname') diff --git a/camelot/io.py b/camelot/io.py index f581735..d78ae57 100644 --- a/camelot/io.py +++ b/camelot/io.py @@ -88,5 +88,5 @@ def read_pdf(filepath, pages='1', flavor='lattice', **kwargs): validate_input(kwargs, flavor=flavor) p = PDFHandler(filepath, pages) kwargs = remove_extra(kwargs, flavor=flavor) - tables, __ = p.parse(flavor=flavor, **kwargs) + tables = p.parse(flavor=flavor, **kwargs) return tables \ No newline at end of file diff --git a/camelot/parsers/base.py b/camelot/parsers/base.py index 3ffe146..5035966 100644 --- a/camelot/parsers/base.py +++ b/camelot/parsers/base.py @@ -1,6 +1,5 @@ import os -from ..core import Geometry from ..utils import get_page_layout, get_text_objects @@ -17,5 +16,4 @@ class BaseParser(object): self.horizontal_text = get_text_objects(self.layout, ltype="lh") self.vertical_text = get_text_objects(self.layout, ltype="lv") self.pdf_width, self.pdf_height = self.dimensions - self.rootname, __ = os.path.splitext(self.filename) - self.g = Geometry() \ No newline at end of file + self.rootname, __ = os.path.splitext(self.filename) \ No newline at end of file diff --git a/camelot/plotting.py b/camelot/plotting.py index 9c06887..9e7e7a3 100644 --- a/camelot/plotting.py +++ b/camelot/plotting.py @@ -8,8 +8,8 @@ def plot_text(text): ax = fig.add_subplot(111, aspect='equal') xs, ys = [], [] for t in text: - xs.extend([t[0], t[1]]) - ys.extend([t[2], t[3]]) + xs.extend([t[0], t[2]]) + ys.extend([t[1], t[3]]) ax.add_patch( patches.Rectangle( (t[0], t[1]), @@ -57,9 +57,7 @@ def plot_joint(image): for coord in table_bbox[k]: x_coord.append(coord[0]) y_coord.append(coord[1]) - max_x, max_y = max(x_coord), max(y_coord) plt.plot(x_coord, y_coord, 'ro') - plt.axis([0, max_x + 100, max_y + 100, 0]) plt.imshow(img) plt.show()