Skip to content

Commit

Permalink
Fix table auto detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak-mehta committed Nov 23, 2018
1 parent 4287ae9 commit 4f6b414
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 44 deletions.
4 changes: 2 additions & 2 deletions excalibur/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ class GhostscriptNotFound(Exception): pass
if len(tables):
lattice_areas = []
for table in tables:
x1, y1, x2, y2 = tables[0]._bbox
x1, y1, x2, y2 = table._bbox
lattice_areas.append((x1, y2, x2, y1))
# stream
parser = Stream()
tables = parser.extract_tables(filepath)
if len(tables):
stream_areas = []
for table in tables:
x1, y1, x2, y2 = tables[0]._bbox
x1, y1, x2, y2 = table._bbox
stream_areas.append((x1, y2, x2, y1))

detected_areas[page] = {
Expand Down
78 changes: 39 additions & 39 deletions excalibur/utils/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@


def get_pages(filename, pages):
"""Converts pages string to list of ints.
"""Converts pages string to list of ints.
Parameters
----------
filename : str
Path to PDF file.
pages : str, optional (default: '1')
Comma-separated page numbers.
Example: 1,3,4 or 1,4-end.
Parameters
----------
filename : str
Path to PDF file.
pages : str, optional (default: '1')
Comma-separated page numbers.
Example: 1,3,4 or 1,4-end.
Returns
-------
N : int
Total pages.
P : list
List of int page numbers.
Returns
-------
N : int
Total pages.
P : list
List of int page numbers.
"""
page_numbers = []
inputstream = open(filename, 'rb')
infile = PdfFileReader(inputstream, strict=False)
N = infile.getNumPages()
if pages == '1':
page_numbers.append({'start': 1, 'end': 1})
"""
page_numbers = []
inputstream = open(filename, 'rb')
infile = PdfFileReader(inputstream, strict=False)
N = infile.getNumPages()
if pages == '1':
page_numbers.append({'start': 1, 'end': 1})
else:
if infile.isEncrypted:
infile.decrypt(self.password)
if pages == 'all':
page_numbers.append({'start': 1, 'end': infile.getNumPages()})
else:
if infile.isEncrypted:
infile.decrypt(self.password)
if pages == 'all':
page_numbers.append({'start': 1, 'end': infile.getNumPages()})
else:
for r in pages.split(','):
if '-' in r:
a, b = r.split('-')
if b == 'end':
b = infile.getNumPages()
page_numbers.append({'start': int(a), 'end': int(b)})
else:
page_numbers.append({'start': int(r), 'end': int(r)})
inputstream.close()
P = []
for p in page_numbers:
P.extend(range(p['start'], p['end'] + 1))
return sorted(set(P)), N
for r in pages.split(','):
if '-' in r:
a, b = r.split('-')
if b == 'end':
b = infile.getNumPages()
page_numbers.append({'start': int(a), 'end': int(b)})
else:
page_numbers.append({'start': int(r), 'end': int(r)})
inputstream.close()
P = []
for p in page_numbers:
P.extend(range(p['start'], p['end'] + 1))
return sorted(set(P)), N


def save_page(filepath, page_number):
Expand Down
9 changes: 8 additions & 1 deletion excalibur/www/static/js/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,16 @@ const renderTableAreas = function (page, tableAreas) {
};

const onDetectAreasClick = (e) => {
const flavor = e.getAttribute('data-flavor');
for (let page in detectedAreas) {
let flavor = '';
if (detectedAreas[page]['lattice'] != null) {
flavor = 'lattice';
} else {
flavor = 'stream';
}
renderTableAreas(page, detectedAreas[page][flavor]);
onFlavorChange();
document.getElementById('flavors').value = flavor.charAt(0).toUpperCase() + flavor.slice(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions excalibur/www/templates/workspace.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ <h6 class="dropdown-header">Saved Rules</h6>
{% endif %}
</div>
</div>
<button type="button" class="btn btn-secondary detect-areas mr-2" data-flavor="lattice" onclick="onDetectAreasClick(this)"><i class="fas fa-eye mr-2"></i>Autodetect Tables</button>
<button type="button" id="reset-areas" class="btn btn-secondary reset-areas mr-2" onclick="resetTableAreas()"><i class="fas fa-trash-alt mr-2"></i>Clear Selections</button>
<button type="button" class="btn btn-secondary detect-areas mr-2" onclick="onDetectAreasClick(this)"><i class="fas fa-eye mr-2"></i>Autodetect Tables</button>
<button type="button" id="reset-areas" class="btn btn-secondary reset-areas mr-2" onclick="resetTableAreas()"><i class="fas fa-trash-alt mr-2"></i>Clear Tables</button>
</div>
</section>
<section class="col-md-2">
Expand Down

0 comments on commit 4f6b414

Please sign in to comment.