0

I am using the FPDF library in python to create a report, it contains the Arial font, and it needs a .ttf to work correctly when generating the report.

pdf = PDF(orientation = 'L', unit = 'mm', format = 'A4')
pdf.add_font('Arial', '', "/var/www/johannasenvironment/JohannasEnviroment/JohannasEnviroment/treasuryEmails/mails/arial.ttf", uni=True)

At the moment of executing the program, it does not find the arial.ttf file that is in the given path, I already tried with relative path and absolute path, and it still does not find the file. In windows it works correctly, I don't know what happens when you pass it to linux.

I am doing something wrong? Should it be implemented differently when I work on linux? if so, how can i do it?

I appreciate your collaboration

When doing the command: ls -lh

total 524K
-rwxrwxrwx 1 root          root           596 feb 25 08:36 arial.cw127.pkl
-rwxrwxrwx 1 root          root          130K feb 25 08:36 arial.pkl
-rwxrwxrwx 1 root          root          359K feb 25 08:36 arial.ttf
-rwxrwxrwx 1 root          root           11K feb 25 16:12 formatPays.py
-rwxrwxrwx 1 root          root           617 feb 25 08:36 format.sql
-rwxrwxrwx 1 root          root          2,3K feb 25 08:36 mailsFunctions.py
drwxrwxrwx 2 administrador administrador 4,0K feb 25 16:13 __pycache__
-rwxrwxrwx 1 root          root           607 feb 25 08:36 validations.py

I add error image with its traceback enter image description here

  • can you `ls -lh "/var/www/johannasenvironment/JohannasEnviroment/JohannasEnviroment/treasuryEmails/mails/arial.ttf"` – Minsky Feb 25 '22 at 22:35
  • I left it at the question – Sebastian Narvaez Feb 25 '22 at 22:40
  • And what is the output when you exec the script? It may be that you don't have permissions to any of those dirs in the path.. – Minsky Feb 25 '22 at 22:57
  • aalways put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Feb 26 '22 at 00:49
  • in question you show that you check `ls -lh` but it doesn't show if you in correct folder - maybe your full path is wrong. You should check `ls -lh ...your path for code...` – furas Feb 26 '22 at 00:51
  • 1
    Do you really have two `JohannasEnviroment` in your real path `"/var/www/johannasenvironment/JohannasEnviroment/JohannasEnviroment/treasuryEmails/mails/arial.ttf"` – furas Feb 26 '22 at 00:52
  • Since I am working on a django project, the folder structure is as shown, I compared the path many times but everything is correct, I do not understand why it does not find the file that loads the source – Sebastian Narvaez Feb 26 '22 at 01:34

1 Answers1

0

SOLUTION: So that linux can find the .ttf fonts, they must be in the folder that stores the fonts belonging to the operating system. Just paste the font in "arial.ttf" at: /usr/share/fonts/truetype/freefont