【发布时间】:2020-02-20 13:09:15
【问题描述】:
我正在 python3.7 中创建一个解析器,它将 xml 文件作为输入并创建 PDF 文件作为输出。我正在使用reportlab 3.5,除了一件事外一切正常。我正在解析的文本使用了一种名为“Junicode”的字体。字体使用正确,除了变音符号(应该在另一个字母上方的字母,如“´”超过“e”,如这个é)被向右移动。这里有一个例子:
我正在使用 SimpleDocTemplate,文本进入表格。我稍微简化了代码:
pdfmetrics.registerFont(TTFont('Junicode', './fonts/Junicode.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeBd', './fonts/Junicode-Bold.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeBI', './fonts/Junicode-BoldItalic.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeIt', './fonts/Junicode-Italic.ttf'))
document = SimpleDocTemplate("output_pdf/" + os.path.splitext(os.path.basename(imgfile))[0] + ".pdf",
pagesize=self.canvas_size,
rightMargin=Helpers.mm_to_pts(self.margin_right),
leftMargin=Helpers.mm_to_pts(self.margin_left),
topMargin=Helpers.mm_to_pts(self.margin_top),
bottomMargin=Helpers.mm_to_pts(self.margin_bottom))
frame = Frame(document.leftMargin, document.bottomMargin, document.width, document.height)
text_template = PageTemplate(id='textpage', frames=[frame], onPage=self.__draw_text_page)
document.addPageTemplates([text_template])
page_flow = [some_other_stuff , NextPageTemplate('textpage'), PageBreak()]
[... code to get line from xml]
table_data.append(['', line])
[...]
table_styles = [('ALIGN', (0, 0), (0, -1), 'RIGHT'),
('ALIGN', (2, 0), (2, -1), 'RIGHT'),
('SIZE', (0, 0), (-1, -1), self.font_size),
('FONT', (0, 0), (-1, -1), 'Junicode'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ]
table = Table(table_data, rowHeights=self.table_row_height)
table.setStyle(TableStyle(table_styles))
page_flow.append(table)
document.build(page_flow)
我试图让字母上方的变音符号,f.e.在上图中,我希望 90 度倾斜的“:”位于 y 上方。
有谁知道这是从哪里来的,是否有解决方案?
谢谢, 保罗
【问题讨论】:
标签: python python-3.x reportlab