V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sky395
V2EX  ›  Python

pymupdf 生成的中文 pdf 是乱码

  •  
  •   sky395 · 2017-11-13 14:53:48 +08:00 · 3673 次点击
    这是一个创建于 2357 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请教一下,下面代码生成的 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()

    2 条回复    2017-11-13 17:57:48 +08:00
    sky395
        1
    sky395  
    OP
       2017-11-13 15:51:37 +08:00
    召唤大神 ing........
    manzhiyong
        2
    manzhiyong  
       2017-11-13 17:57:48 +08:00   ❤️ 1
    用 reportlab 吧,reportlab 找个中文的 ttf 字体,指定下路径,是可以正常输出中文的,pymupdf 好像有 bug
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:58 · PVG 06:58 · LAX 15:58 · JFK 18:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.