Reputation: 559
I have a csv with utf-8 characters that I want to convert to a pdf using Python's fpdf package.
When I execute the following code, I receive the error, RuntimeError: TTF Font file not found: C:\Windows\Fonts\DejaVuSansCondensed.ttf
Here is the full stack trace:
Traceback (most recent call last):
File "C:/Users/abcd/PycharmProjects/bronze/pdfParser.py", line 40, in <module>
pdf.add_font('DejaVu', '', "C:\Windows\Fonts\DejaVuSansCondensed.ttf", uni=True)
File "C:\Users\abcd\PycharmProjects\bronze\venv\lib\site-packages\fpdf\fpdf.py", line 469, in add_font
raise RuntimeError("TTF Font file not found: %s" % fname)
RuntimeError: TTF Font file not found: C:\Windows\Fonts\DejaVuSansCondensed.ttf
Here are the relevant parts of my code:
from fpdf import FPDF
lines = []
with open("intake.csv", "r") as f:
data = f.readlines()
for line in data:
lines.append(line[1:-1].split('","'))
pdf = FPDF()
pdf.add_page()
# This following line SHOULD work, but does not
pdf.add_font('DejaVu', '', "C:\Windows\Fonts\DejaVuSansCondensed.ttf", uni=True)
pdf.set_font('DejaVu', '', 14)
for entry in range(0, len(lines[0])):
question = str(entry) + ") " + lines[0][entry]
pdf.cell(40, 10, question, ln=1)
pdf.cell(40, 10, lines[1][entry], ln=1)
# make a new line
pdf.cell(40, 10, "", ln=1)
pdf.cell(40, 10, "", ln=1)
pdf.output("tuto-test.pdf", "F")
When I run this I should get a nice little pdf. Instead it yells at me that I do not have a font installed.
I absolutely do have this font installed on my PC. I've installed the font directly and received a message from my OS, "Font is already installed" basically. I have also restarted both my PC and my PyCharm program.
I found a Google Groups thread related to my problem but I couldn't figure out what the request.folder
thing is (NOT requests, "request", no s). https://groups.google.com/g/web2py/c/UZf7qJ6KDa8
Seems like a really niche problem so if anyone can solve my problem I'll be really impressed. Thanks
Upvotes: 1
Views: 4879
Reputation:
Smells like a windows permission issue, according to official docs:
os.path.exists(path) Return True if path refers to an existing path or an open file descriptor. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
so you should either give yourself permissions to access that folder (not recommended), or just copy the font to a directory you own.
Upvotes: 3