From 08efb465994b4e18be7b61a75b46f9fde93fedc1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Nov 2019 17:38:13 +0530 Subject: [PATCH] PDF Output: Fix incorrect rendering if the input document has too many anchors. Fixes #1854345 [too many ids in input causes zoomed out converted pdf](https://bugs.launchpad.net/calibre/+bug/1854345) --- src/calibre/ebooks/pdf/html_writer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/pdf/html_writer.py b/src/calibre/ebooks/pdf/html_writer.py index da998bd8da..02770176f6 100644 --- a/src/calibre/ebooks/pdf/html_writer.py +++ b/src/calibre/ebooks/pdf/html_writer.py @@ -13,7 +13,7 @@ import signal import sys from collections import namedtuple from io import BytesIO -from itertools import repeat +from itertools import count, repeat from operator import attrgetter, itemgetter from html5_parser import parse @@ -422,14 +422,21 @@ def add_anchors_markup(root, uuid, anchors): ) div.text = '\n\n' body.append(div) + c = count() def a(anchor): + num = next(c) a = div.makeelement( XHTML('a'), href='#' + anchor, style='min-width: 10px !important; min-height: 10px !important; border: solid 1px !important;' ) a.text = a.tail = ' ' + if num % 8 == 0: + # prevent too many anchors on a line as it causes chromium to + # rescale the viewport + a.tail = '\n' div.append(a) + a.count = 0 tuple(map(a, anchors)) a(uuid)