Reputation: 412
How do I add unicode font in my GAE application using PyFPDF?
I have gone through the tutorials on: 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.
The problem here is PyFPDF will create the metrics file (.pkl) in the folder, it required write permission, GAE doesn't allow to write file, how should I do it?
Thank you!
Joel
Upvotes: 3
Views: 1174
Reputation: 32737
While the accepted solution works it requires you to include the fpdf source files into your project, which is not ideal if you just want to work with the fpdf package.
A solution that also works without changing the source file is to set the global variable FPDF_CACHE_MODE
via the set_global(
) function, which is provided in the FPDF package.
Example:
import fpdf
fpdf.set_global("FPDF_CACHE_MODE", 1)
Upvotes: 2
Reputation: 1916
The 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 file of the library. Therefore you need to modify this file and set the constant to 1 before you do the deploy.
Upvotes: 3