【问题标题】:Unreadable text after printing to PDF打印为 PDF 后无法阅读的文本
【发布时间】:2019-03-20 06:35:39
【问题描述】:

我需要将文本打印为 PDF,但我正在打印的文本不是 ascii。根据我的代码输出,它会生成类似这样的内容

[][][][][][][](一个盒子;))

我正在尝试弄清楚如何将非 ascii 文本打印为 PDF。谢谢!

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

def sample():
    pdf = fpdf.FPDF()
    pdf.add_page()
    text = '안녕하세요'
    pdf.add_font('DejaVu', '', 'fpdf\\unifont\\DejaVuSansCondensed.ttf', uni=True)
    pdf.set_font('DejaVu', '', 9)

    pdf.text(x=data_column, y=start_y + (3 * charheight),
                 txt=str(u": {0}".format(text)))

【问题讨论】:

    标签: python unicode fonts fpdf


    【解决方案1】:

    您使用的字体不支持韩文字符。 fpdf docs 使用韩文的 eunjin 字体:

    # Add a Alee Unicode font (uses UTF-8)
    # General purpose Hangul truetype fonts that contain Korean syllable 
    # and Latin9 (iso8859-15) characters.
    pdf.add_font('eunjin', '', 'Eunjin.ttf', uni=True)
    pdf.set_font('eunjin', '', 14)
    pdf.write(8, u'Korean: 안녕하세요')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 2013-10-31
      相关资源
      最近更新 更多