I am attempting to create a PDF document using pisa which includes user input. The user input can be in can be in other languages. When attempting to input Chinese or Japanese the characters are displayed as black boxes. How do I get the PDF to display correctly even when I do not know what language the user has entered?

Here is a sample of what I am attempting:

import ho.pisa as pisa
import StringIO
import sys

data = """
<html>
    <head>
        <title>Testing</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
    </head>
    <body>
        <p>%s</p>
    </body>
</html>
"""

text = ""
for line in sys.stdin:
    text += line

pisa.pisaDocument(StringIO.StringIO(data % text), file('final.pdf', 'w'), encoding='UTF-8')
有帮助吗?

解决方案

The default fonts pisa uses do not support Chinese or Japanese characters. I was able to get the characters to display by including a font file with support for these characters and using it in the css.

@font-face {
   font-family: OtherFont;
   src: url(font/OtherFont.ttf);
}
body {
   font-family: OtherFont;
}

See Section 8 of this documentation

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top