Alfa Rojo
Alfa Rojo

Reputation: 194

Noto font cannot be added in FPDF?

I have this method to add pages with specific fonts depending on the given language, but for some reason, now it throws error every time. The .ttf are located in the root

*Using Python 3.12 in AWS Lambda function

#This works 100%
def add_new_page():
    pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
    pdf.set_font('DejaVu', size=12)
    pdf.add_page()
    print('Adding new page')

Now I change it to

def add_new_page(Language:str):
    try:
        match Language.lower():
            case "japanese":
                print(f"Adding {Language.lower()} languaje to PDF")
                pdf.add_font('NotoCJK', '', 'NotoSansJP-VariableFont_wght.ttf', uni=True)
                pdf.set_font('NotoCJK', size=12)
            case "korean":
                print(f"Adding {Language.lower()} languaje to PDF")
                pdf.add_font('NotoCJK', '', 'NotoSansKR-VariableFont_wght.ttf', uni=True)
                pdf.set_font('NotoCJK', size=12)
            case _:
                print(f"Adding {Language.lower()} languaje to PDF")
                pdf.add_font('NotoSans', '', 'NotoSans-VariableFont_wdth,wght.ttf', uni=True)
                pdf.set_font('NotoSans', size=12)
                
    except Exception as e:
        print(f"Error adding font: {e}") #Prints => Error adding font: 'head'
        pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
        pdf.set_font('DejaVu', size=12)


    pdf.add_page()
    print('Adding new page')

I got the fonts from google fonts When I try Japanese, Korean, Rusian trows the error

Upvotes: 0

Views: 14

Answers (0)

Related Questions