Winzige Zahlen in ReportLabs InhaltsverzeichnisPython

Python-Programme
Anonymous
 Winzige Zahlen in ReportLabs Inhaltsverzeichnis

Post by Anonymous »

Ich habe ein Beispiel aus der ReportLab -Dokumentation zum Hinzufügen eines Inhaltsverzeichnisses verfolgt, und es funktioniert in den meisten Situationen einwandfrei. Wenn jedoch ein Abschnittstitel sehr nahe an der gesamten Seitenbreite liegt, wird die Seitennummer so geschrumpft. Manchmal ist es bis zu dem Punkt geschrumpft, an dem man es überhaupt nicht sehen kann. src = "https://i.static.net/cqmew9gy.png"/>
Sie können sehen, dass mit 3, 4 und 5 die Seitenzahl schrumpft und verschwindet.

Code: Select all

from reportlab.lib.styles import ParagraphStyle as PS
from reportlab.platypus import PageBreak
from reportlab.platypus.paragraph import Paragraph
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
from reportlab.platypus.tableofcontents import TableOfContents
from reportlab.platypus.frames import Frame
from reportlab.lib.units import cm

class MyDocTemplate(BaseDocTemplate):

def __init__(self, filename, **kw):
self.allowSplitting = 0
BaseDocTemplate.__init__(self, filename, **kw)
template = PageTemplate('normal', [Frame(2.5 * cm, 2.5 * cm, 15 * cm, 25 * cm, id='F1')])
self.addPageTemplates(template)

def afterFlowable(self, flowable):
"Registers TOC entries."
if flowable.__class__.__name__ == 'Paragraph':
text = flowable.getPlainText()
style = flowable.style.name
if style == 'Heading1':
self.notify('TOCEntry', (0, text, self.page))
if style == 'Heading2':
self.notify('TOCEntry', (1, text, self.page))

h1 = PS(name='Heading1',
fontSize=14,
leading=16)

h2 = PS(name='Heading2',
fontSize=12,
leading=14,
leftIndent=10)

# Build story.
story = []
toc = TableOfContents()
# For conciseness we use the same styles for headings and TOC entries
toc.levelStyles = [h1, h2]
story.append(toc)
story.append(PageBreak())
story.append(Paragraph('Table of Contents Test', h1))
for i in range(10):
story.append(Paragraph('XXXXX ' * 9 + 'i' * i, h2))

doc = MyDocTemplate('toc_test.pdf')
doc.multiBuild(story)
Ich habe im ReportLab -Quellcode gesucht und festgestellt, dass er wirklich die Seitenzahl schrumpft, bis sie eine Schriftgröße von 1 Pixel erreicht oder erreicht.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post