首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ReportLab生成PDF索引

用ReportLab生成PDF索引
EN

Stack Overflow用户
提问于 2015-12-09 09:35:06
回答 1查看 1.7K关注 0票数 1

我正在通过ReportLab生成PDF文件,但是我找不到任何关于如何生成链接到文件页的索引的文档。ReportLab支持这种类型的特性,还是有其他解决方案?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-10 09:21:50

经过很长时间的搜索,我想出了一个anchor解决方案。虽然我觉得这对我来说不是一个完美的解决方案,但我希望它能帮助到需要帮助的人。

代码语言:javascript
复制
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.platypus import Paragraph, PageBreak, SimpleDocTemplate, Spacer

registerFont(TTFont('Calibri', 'Calibri.ttf')) # Just some font imports
registerFont(TTFont('Calibri-Bold', 'calibrib.ttf'))

pH = ParagraphStyle(name = 'Header', fontName = 'Calibri-Bold', fontSize = 13, leftIndent = 20, firstLineIndent = -20, spaceBefore = 10, leading = 16)
sH = ParagraphStyle(name = 'SubHeader', fontName = 'Calibri', fontSize = 12, leftIndent = 40, firstLineIndent = -20, spaceBefore = 5, leading = 16)

doc = SimpleDocTemplate('Reports\\PDFname.pdf')
story = [Spacer(1, 2 * inch)]

story.append(Paragraph('<a href = page3.html#0>1. First Title</a>', pH)) # Linking the anchor to reference 0
story.append(Paragraph('<a href = page3.html#1>1.1. First Subtitle</a>', sH)) # Linking the anchor to reference 1
story.append(PageBreak())

story.append(Paragraph('<a name = page3.html#0></a> 1. First Title', pH)) # Creating anchor with reference 0
story.append(Paragraph('<a name = page3.html#1></a><br/> 1.1. First Subtitle', style)) # Creating anchor with reference 1

doc.build(story)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34175264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档