2

我想在 django 中使用 Pisa 在 pdf 文件中添加“comic”字体。Pisa 的默认字体是 Helvetica 文本,但我想要在我生成的 pdf 中使用更多字体,如 arial、comic、symbol、verdana 等。

请帮忙!

4

1 回答 1

2

嗨,我得到了答案,如果您使用的是编辑器,则将其保存在“内容”字符串中。然后以下代码将起作用。

contents = "<html><head><style type='text/css'>@font-face {font-family: comic sans ms; src: url(media/fonts/comic.ttf);}</style></head><body> " + contents + " </body></html>"
template = Template(contents)

context = Context()
template_rendered = template.render(context)

name="mypdf.pdf"

import ho.pisa as pisa
pfile = file(name, 'wb')
pisa.CreatePDF(template_rendered.encode("UTF-8"), pfile ,encoding='UTF-8')
pfile.close()

希望存在许多其他答案,但就我而言,使用 tinymce 编辑器,此解决方案有效。

于 2011-02-03T14:55:37.097 回答