Reorganize around getting bboxes for visible/invisible text
This commit is contained in:
@@ -28,6 +28,7 @@ import xml.etree.ElementTree as ET
|
||||
from pikepdf import PdfMatrix
|
||||
import pikepdf
|
||||
|
||||
from .layout import get_textblocks, bboxes
|
||||
from ..exec import ghostscript
|
||||
from ..helpers import fspath
|
||||
|
||||
@@ -597,7 +598,6 @@ def _pdf_get_pageinfo(pdf, pageno: int, infile, xmltext):
|
||||
# pageinfo['textinfo'] = _page_get_textblocks(
|
||||
# fspath(infile), pageno, xmltext=xmltext)
|
||||
|
||||
from .layout import get_textblocks
|
||||
with Path(infile).open('rb') as f:
|
||||
pageinfo['objects'] = get_textblocks(f, pageno)
|
||||
|
||||
@@ -605,17 +605,6 @@ def _pdf_get_pageinfo(pdf, pageno: int, infile, xmltext):
|
||||
width_pt = mediabox[2] - mediabox[0]
|
||||
height_pt = mediabox[3] - mediabox[1]
|
||||
|
||||
def bboxes(hierarchical_textinfo):
|
||||
from pdfminer.layout import LTTextLine, LTTextBox
|
||||
for obj in hierarchical_textinfo:
|
||||
if isinstance(hierarchical_textinfo, (LTTextLine, LTTextBox)):
|
||||
yield hierarchical_textinfo.bbox
|
||||
else:
|
||||
try:
|
||||
yield from bboxes(obj)
|
||||
except TypeError:
|
||||
continue
|
||||
|
||||
pageinfo['has_text'] = _page_has_text(
|
||||
bboxes(pageinfo['objects']), width_pt, height_pt)
|
||||
|
||||
@@ -748,17 +737,6 @@ class PageInfo:
|
||||
return self._pageinfo['images']
|
||||
|
||||
def get_textareas(self, visible=True, invisible=True):
|
||||
def bboxes(objs):
|
||||
from pdfminer.layout import LTTextBox
|
||||
for obj in objs:
|
||||
if isinstance(obj, LTTextBox):
|
||||
yield obj.bbox
|
||||
else:
|
||||
try:
|
||||
yield from bboxes(obj)
|
||||
except TypeError:
|
||||
continue
|
||||
|
||||
if visible:
|
||||
yield from bboxes(self._pageinfo['objects'][0])
|
||||
if invisible:
|
||||
|
||||
@@ -23,7 +23,8 @@ from pdfminer.pdfpage import PDFPage
|
||||
from pdfminer.utils import matrix2str, bbox2str, fsplit
|
||||
from pdfminer.pdffont import PDFUnicodeNotDefined
|
||||
from pdfminer.layout import (
|
||||
LTChar, LTContainer, LTLayoutContainer, LTPage, LTTextLine, LAParams
|
||||
LTChar, LTContainer, LTLayoutContainer, LTPage, LTTextLine, LAParams,
|
||||
LTTextBox
|
||||
)
|
||||
|
||||
from pdfminer.converter import PDFLayoutAnalyzer
|
||||
@@ -121,7 +122,7 @@ class TextPositionTracker(PDFLayoutAnalyzer):
|
||||
return item.adv
|
||||
|
||||
def handle_undefined_char(self, font, cid):
|
||||
log.info('undefined: %r, %r', font, cid)
|
||||
#log.info('undefined: %r, %r', font, cid)
|
||||
return '(cid:%d)' % cid
|
||||
|
||||
def receive_layout(self, ltpage):
|
||||
@@ -141,3 +142,14 @@ def get_textblocks(infile, pageno):
|
||||
interp.process_page(next(page))
|
||||
|
||||
return dev.get_result()
|
||||
|
||||
|
||||
def bboxes(hierarchical_textinfo):
|
||||
for obj in hierarchical_textinfo:
|
||||
if isinstance(hierarchical_textinfo, (LTTextBox)):
|
||||
yield hierarchical_textinfo.bbox
|
||||
else:
|
||||
try:
|
||||
yield from bboxes(obj)
|
||||
except TypeError:
|
||||
continue
|
||||
|
||||
@@ -145,7 +145,7 @@ def test_pickle(resources):
|
||||
# For multiprocessing we must be able to pickle our information - if
|
||||
# this fails then we are probably storing some unpickleabe pikepdf or
|
||||
# other external data around
|
||||
filename = resources / 'formxobject.pdf'
|
||||
filename = resources / 'graph_ocred.pdf'
|
||||
pdf = pdfinfo.PdfInfo(filename)
|
||||
pickle.dumps(pdf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user