Domanda

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')
È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top