Add verbose
This commit is contained in:
+5
-2
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import cv2
|
||||
@@ -160,7 +161,7 @@ class Lattice:
|
||||
"""
|
||||
|
||||
def __init__(self, pdfobject, fill=None, scale=15, jtol=2, mtol=2,
|
||||
invert=False, debug=None):
|
||||
invert=False, debug=None, verbose=False):
|
||||
|
||||
self.pdfobject = pdfobject
|
||||
self.fill = fill
|
||||
@@ -169,6 +170,7 @@ class Lattice:
|
||||
self.mtol = mtol
|
||||
self.invert = invert
|
||||
self.debug = debug
|
||||
self.verbose = verbose
|
||||
self.tables = {}
|
||||
if self.debug is not None:
|
||||
self.debug_images = {}
|
||||
@@ -184,6 +186,7 @@ class Lattice:
|
||||
Dictionary with page number as key and list of tables on that
|
||||
page as value.
|
||||
"""
|
||||
vprint = print if self.verbose else lambda *a, **k: None
|
||||
self.pdfobject.split()
|
||||
self.pdfobject.convert()
|
||||
for page in self.pdfobject.extract():
|
||||
@@ -273,7 +276,7 @@ class Lattice:
|
||||
ar = remove_empty(ar)
|
||||
ar = [list(o) for o in ar]
|
||||
page_tables.append(encode_list(ar))
|
||||
print pkey # verbose
|
||||
vprint(pkey)
|
||||
self.tables[pkey] = page_tables
|
||||
|
||||
if self.debug is not None:
|
||||
|
||||
@@ -114,6 +114,8 @@ class Pdf:
|
||||
def split(self):
|
||||
"""Splits pdf into single page pdfs.
|
||||
"""
|
||||
if not self.pdfname.endswith('.pdf'):
|
||||
raise TypeError("Only PDF format is supported.")
|
||||
infile = PdfFileReader(open(self.pdfname, 'rb'), strict=False)
|
||||
for p in self.pagenos:
|
||||
page = infile.getPage(p - 1)
|
||||
|
||||
+5
-2
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@@ -105,13 +106,14 @@ class Stream:
|
||||
"""
|
||||
|
||||
def __init__(self, pdfobject, ncolumns=0, columns=None, ytol=2,
|
||||
debug=False):
|
||||
debug=False, verbose=False):
|
||||
|
||||
self.pdfobject = pdfobject
|
||||
self.ncolumns = ncolumns
|
||||
self.columns = columns
|
||||
self.ytol = ytol
|
||||
self.debug = debug
|
||||
self.verbose = verbose
|
||||
self.tables = {}
|
||||
if self.debug:
|
||||
self.debug_text = {}
|
||||
@@ -125,6 +127,7 @@ class Stream:
|
||||
Dictionary with page number as key and list of tables on that
|
||||
page as value.
|
||||
"""
|
||||
vprint = print if self.verbose else lambda *a, **k: None
|
||||
self.pdfobject.split()
|
||||
for page in self.pdfobject.extract():
|
||||
p, __, text, __, __ = page
|
||||
@@ -172,7 +175,7 @@ class Stream:
|
||||
[ar[r_idx][c_idx], t.get_text().strip()])
|
||||
else:
|
||||
ar[r_idx][c_idx] = t.get_text().strip()
|
||||
print pkey # verbose
|
||||
vprint(pkey)
|
||||
self.tables[pkey] = [encode_list(ar)]
|
||||
|
||||
if self.pdfobject.clean:
|
||||
|
||||
Reference in New Issue
Block a user