From 2482296e2bc9065895350a1622c30c4c8827e0a8 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 14 Apr 2018 17:24:21 -0700 Subject: [PATCH] hocr: avoid division by zero Issue #253 - PDF that produces the error is not available, but if font_width is zero, chances are the text is nonprinting characters, so suppress it. --- src/ocrmypdf/hocrtransform.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ocrmypdf/hocrtransform.py b/src/ocrmypdf/hocrtransform.py index 4c8bbe90..edd674ff 100755 --- a/src/ocrmypdf/hocrtransform.py +++ b/src/ocrmypdf/hocrtransform.py @@ -322,8 +322,11 @@ class HocrTransform(): dy = baseline_y2 - cursor[1] text.moveCursor(dx, dy) - text.setHorizScale(100 * box_width / font_width) - text.textOut(elemtxt) + # If reportlab tells us this word is 0 units wide, our best seems + # to be to suppress this text + if font_width > 0: + text.setHorizScale(100 * box_width / font_width) + text.textOut(elemtxt) pdf.drawText(text)