I have a python google cloud function that should create a pdf when triggered, but the code seems to breakdown, seemingly because of the font, see below.
I tested the workflow with my local installation of fpdf2 and everything worked fine, but it seems to be breaking up when I run it on the GC console.
The fonts are stored in a github repo.
Code below –
class PDF(FPDF):
import logging
....
def header(self):
..........
self.add_font('Spectral', '', fname = repo.get_contents("Style/Spectral/spectrallight.php").decoded_content)
self.add_font('Spectral', 'B', fname = repo.get_contents("Style/Spectral/spectralb.php").decoded_content)
self.add_font('SpectralB', 'B', fname = repo.get_contents("Style/Spectral/spectralb.php").decoded_content)
self.add_font('Spectral', 'BI', fname = repo.get_contents("Style/Spectral/spectralbi.php").decoded_content)
self.add_font('Spectral', 'I', fname = repo.get_contents("Style/Spectral/spectrali.php").decoded_content)
.....
Here’s the error I’m getting –
.......File "/workspace/main.py", line 378, in generation
pdf.add_page()
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/fpdf/fpdf.py", line 904, in add_page
self.header()
File "/workspace/main.py", line 217, in header
self.add_font('Spectral', '', fname = repo.get_contents("Style/Spectral/spectrallight.php").decoded_content, uni = False)
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/fpdf/fpdf.py", line 1810, in add_font
raise ValueError(
ValueError: Unsupported font file extension: . add_font() used to accept .pkl file as input, but for security reasons this feature is deprecated since v2.5.1 and has been removed in v2.5.3
At first I used .ttf fonts from Google Fonts, I’ve also tried actually using plk fonts, now .php, but I keep get the same error.
I’ve also tried parsing the fonts with BytesIO, tried changing my fpfd2 to 2.5.1 (the function wouldn’t deploy”…and a whole host of other fixes…
Jason Vuka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.