i want to add "comic" font in pdf file by using Pisa in django. Pisa default font is Helvetica for text, but i want more fonts in my generated pdf, like arial,comic, symbol, verdana etc.
我想在pdf文件中添加“comic”字体,使用django中的Pisa。Pisa默认字体是文本的Helvetica字体,但我想在生成的pdf中使用更多的字体,如arial、comic、symbol、verdana等。
Please help!
请帮助!
1 个解决方案
#1
2
hi i got the answer, if you are using editor, then save its out put in "contents" string. Then following code will work.
你好,我得到了答案,如果你正在使用编辑器,那么将它保存在“内容”字符串中。然后遵循代码就可以了。
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()
Hopefully many others answers exist but in my case, using tinymce editor, this solution works.
希望还有其他的答案存在,但是在我的例子中,使用tinymce编辑器,这个解决方案是有效的。
#1
2
hi i got the answer, if you are using editor, then save its out put in "contents" string. Then following code will work.
你好,我得到了答案,如果你正在使用编辑器,那么将它保存在“内容”字符串中。然后遵循代码就可以了。
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()
Hopefully many others answers exist but in my case, using tinymce editor, this solution works.
希望还有其他的答案存在,但是在我的例子中,使用tinymce编辑器,这个解决方案是有效的。