PyFPDF 在 Google App Engine 中添加 Unicode 字体
PyFPDF Add Unicode Font in Google App Engine
如何使用 PyFPDF 在我的 GAE 应用程序中添加 unicode 字体?
我已完成以下教程:
https://pyfpdf.readthedocs.io/en/latest/Unicode/index.html#metric-files
FPDF will try to automatically generate metrics (i.e. character widths) about TTF font files to speed up their processing.
Such metrics are stored using the Python Pickle format (.pkl extension), by default in the font directory (ensure read and write permission!). Additional information about the caching mechanism is defined in the add_font reference.
这里的问题是 PyFPDF 会在文件夹中创建指标文件 (.pkl),它需要写权限,GAE 不允许写文件,我该怎么办?
谢谢!
乔尔
库的add_font() function makes use of the FPDF_CACHE_MODE constant which looks like is the one specifying if writing the .pkl files or not. This constant may have three values (either 0, 1 or 2). If settled to 1 then it does not write the .pkl files. This constant is defined in the fpdf.py文件。因此,您需要在部署之前修改此文件并将常量设置为 1。
虽然公认的解决方案有效,但它要求您将 fpdf 源文件包含到您的项目中,如果您只想使用 fpdf 包,这并不理想。
在不更改源文件的情况下也可以使用的解决方案是通过 FPDF 包中提供的 set_global(
) 函数设置全局变量 FPDF_CACHE_MODE
。
示例:
import fpdf
fpdf.set_global("FPDF_CACHE_MODE", 1)
如何使用 PyFPDF 在我的 GAE 应用程序中添加 unicode 字体?
我已完成以下教程: https://pyfpdf.readthedocs.io/en/latest/Unicode/index.html#metric-files
FPDF will try to automatically generate metrics (i.e. character widths) about TTF font files to speed up their processing.
Such metrics are stored using the Python Pickle format (.pkl extension), by default in the font directory (ensure read and write permission!). Additional information about the caching mechanism is defined in the add_font reference.
这里的问题是 PyFPDF 会在文件夹中创建指标文件 (.pkl),它需要写权限,GAE 不允许写文件,我该怎么办?
谢谢!
乔尔
库的add_font() function makes use of the FPDF_CACHE_MODE constant which looks like is the one specifying if writing the .pkl files or not. This constant may have three values (either 0, 1 or 2). If settled to 1 then it does not write the .pkl files. This constant is defined in the fpdf.py文件。因此,您需要在部署之前修改此文件并将常量设置为 1。
虽然公认的解决方案有效,但它要求您将 fpdf 源文件包含到您的项目中,如果您只想使用 fpdf 包,这并不理想。
在不更改源文件的情况下也可以使用的解决方案是通过 FPDF 包中提供的 set_global(
) 函数设置全局变量 FPDF_CACHE_MODE
。
示例:
import fpdf
fpdf.set_global("FPDF_CACHE_MODE", 1)