pymupdf 生成的中文 pdf 是乱码

2017-11-13 14:53:48 +08:00
 sky395

请教一下,下面代码生成的 pdf 是乱码,环境为 python3+windowns 10

谢谢大家!

import fitz

ofn = '3.pdf'

b = "你好! hello !"

width, height = fitz.PaperSize("a4")

fontsz = 10

lineheight = fontsz * 1.2

ffile = "C:/windows/fonts/consola.ttf"

font = "F0"

doc = fitz.open()

doc.insertPage(-1, fontsize = fontsz, text = b, fontname = font, fontfile = ffile, width = width, height = height)

doc.save(ofn, garbage=4, deflate=True)

doc.close()

3687 次点击
所在节点    Python
2 条回复
sky395
2017-11-13 15:51:37 +08:00
召唤大神 ing........
manzhiyong
2017-11-13 17:57:48 +08:00
用 reportlab 吧,reportlab 找个中文的 ttf 字体,指定下路径,是可以正常输出中文的,pymupdf 好像有 bug

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/405979

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX