From c1c8a81227db59f14abe6890b4477d70bd3638e4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Oct 2024 22:08:30 +0530 Subject: [PATCH] New PDF engine: Ignore dive by zero when average char width is zero --- src/calibre/ebooks/pdf/reflow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/pdf/reflow.py b/src/calibre/ebooks/pdf/reflow.py index cd92f441c3..777dd22039 100644 --- a/src/calibre/ebooks/pdf/reflow.py +++ b/src/calibre/ebooks/pdf/reflow.py @@ -990,7 +990,10 @@ class Page: frag.indented = 1 # 1em else: # Assume left margin of approx = number of chars # Should check for values approx the same, as with indents - frag.margin_left = int(round((frag.left - left) / frag.average_character_width)+0.5) + try: + frag.margin_left = int(round((frag.left - left) / frag.average_character_width)+0.5) + except ZeroDivisionError: + frag.margin_left = 0 if last_frag is not None \ and frag.bottom - last_frag.bottom \ > stats.para_space*SECTION_FACTOR: