Add corrupt text warning (when using --redo-ocr)
This commit is contained in:
@@ -252,6 +252,13 @@ def is_ocr_required(pageinfo, log, options):
|
||||
"rasterizing text and running OCR anyway"))
|
||||
ocr_required = True
|
||||
elif options.redo_ocr:
|
||||
if pageinfo.has_corrupt_text:
|
||||
log.warning(msg.format(
|
||||
page,
|
||||
"some text on this page cannot be mapped to characters: "
|
||||
"consider using --force-ocr instead")
|
||||
)
|
||||
else:
|
||||
log.info(msg.format(page,
|
||||
"redoing OCR"))
|
||||
ocr_required = True
|
||||
|
||||
@@ -108,7 +108,7 @@ InlineSettings = namedtuple('InlineSettings',
|
||||
ContentsInfo = namedtuple('ContentsInfo',
|
||||
['xobject_settings', 'inline_images', 'found_text', 'found_vector'])
|
||||
|
||||
TextBoxInfo = namedtuple('TextBoxInfo',
|
||||
TextboxInfo = namedtuple('TextboxInfo',
|
||||
['bbox', 'is_visible', 'is_corrupt'])
|
||||
|
||||
|
||||
@@ -603,7 +603,7 @@ def simplify_textboxes(miner):
|
||||
|
||||
visible = (first_char.rendermode != 3)
|
||||
corrupt = (first_char.get_text() == '\ufffd')
|
||||
yield TextBoxInfo(box.bbox, visible, corrupt)
|
||||
yield TextboxInfo(box.bbox, visible, corrupt)
|
||||
|
||||
|
||||
def _pdf_get_pageinfo(pdf, pageno: int, infile, xmltext):
|
||||
@@ -714,6 +714,10 @@ class PageInfo:
|
||||
def has_text(self):
|
||||
return self._pageinfo['has_text']
|
||||
|
||||
@property
|
||||
def has_corrupt_text(self):
|
||||
return any(tbox.is_corrupt for tbox in self._pageinfo['textboxes'])
|
||||
|
||||
@property
|
||||
def has_vector(self):
|
||||
return self._pageinfo['has_vector']
|
||||
|
||||
@@ -35,12 +35,27 @@ from pdfminer.utils import matrix2str, bbox2str, fsplit
|
||||
from ..exceptions import EncryptedPdfError
|
||||
|
||||
|
||||
# Fix pdfminer's regex in name2unicode function
|
||||
# Font cids that are mapped to names of the form /g123 seem to be, by convention
|
||||
# characters with no corresponding Unicode entry. These can be subsetted fonts
|
||||
# or symbolic fonts. There seems to be no way to map /g123 fonts to Unicode,
|
||||
# barring a ToUnicode data structure.
|
||||
pdfminer.encodingdb.STRIP_NAME = re.compile(r'(?![g])([0-9]+)')
|
||||
|
||||
STRIP_NAME = re.compile(r'[0-9]+')
|
||||
|
||||
def name2unicode(name):
|
||||
"""Fix pdfminer's regex in name2unicode function
|
||||
|
||||
Font cids that are mapped to names of the form /g123 seem to be, by convention
|
||||
characters with no corresponding Unicode entry. These can be subsetted fonts
|
||||
or symbolic fonts. There seems to be no way to map /g123 fonts to Unicode,
|
||||
barring a ToUnicode data structure.
|
||||
"""
|
||||
if name in glyphname2unicode:
|
||||
return glyphname2unicode[name]
|
||||
if name.startswith('g'):
|
||||
raise KeyError(name)
|
||||
m = STRIP_NAME.search(name)
|
||||
if not m:
|
||||
raise KeyError(name)
|
||||
return chr(int(m.group(0)))
|
||||
|
||||
pdfminer.encodingdb.name2unicode = name2unicode
|
||||
|
||||
from math import copysign
|
||||
def PDFType3Font__get_height(self):
|
||||
|
||||
Reference in New Issue
Block a user