python unicode 编程 pdf_python – 使用xhtml2pdf将unicode模板转换为pdf的麻烦

我在我的html页面中使用了unicode,它在html页面中正确显示.但是在使用xhtml2pdf将其转换为html时,它会在unicodes中生成黑色实心方框.是否有UTF-8设置以外的unicode设置.我不认为它的unicode问题.

# convert HTML to PDF

pisaStatus = pisa.CreatePDF(

StringIO(sourceHtml.encode('utf-8')),

dest=resultFile)

完整的py代码:

# -*- coding: utf-8 -*-

from xhtml2pdf import pisa

from StringIO import StringIO

source = """

@font-face {

font-family: Preeti;

src: url("preeti.ttf");

}

body {

font-family: Preeti;

}

This is a test

सरल

"""

# Utility function

def convertHtmlToPdf(source):

# open output file for writing (truncated binary)

pdf = StringIO()

pisaStatus = pisa.CreatePDF(StringIO(source.encode('utf-8')), pdf)

# return True on success and False on errors

print "Success: ", pisaStatus.err

return pdf

# Main program

if __name__=="__main__":

print pisa.showLogging()

pdf = convertHtmlToPdf(source)

fd = open("test.pdf", "w+b")

fd.write(pdf.getvalue())

fd.close()

我甚至需要包括font-face?

解决方法:

它部分解决了.提供字体的绝对路径,即

@font-face {

font-family: Preeti;

src: url("c:/static/fonts/preeti.ttf");

}

body {

font-family: Preeti;

}

现在又出现了另一个问题.我有混合文本,部分在unicode和部分正常字体(我想我应该说它是普通字体:D),因为字体已被覆盖,现在正常的字体是在矩形框中.在这种情况下一个空盒子.

标签:python,unicode,flask,xhtml2pdf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值