简体   繁体   English

创建带有比萨和非ASCII字符的PDF

[英]Creating a PDF with pisa and non-ascii characters

I am attempting to create a PDF document using pisa which includes user input. 我正在尝试使用包含用户输入的比萨创建PDF文档。 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? 即使我不知道用户输入了哪种语言,如何使PDF正确显示?

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. 通过包含支持这些字符的字体文件并在CSS中使用它,我能够显示字符。

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

See Section 8 of this documentation 请参阅本文档的第8节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM