Ghmustafa11 commited on
Commit
e2e8dd5
·
verified ·
1 Parent(s): e071999

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  from fpdf import FPDF
 
3
 
4
  # Function to create various types of documents
5
  def generate_document(doc_type, text, style="formal"):
@@ -73,9 +74,13 @@ def generate_pdf(document_text):
73
  pdf = FPDF()
74
  pdf.add_page()
75
 
76
- # Using a font that supports Unicode (DejaVu Sans)
77
- pdf.add_font('DejaVu', '', 'DejaVuSans.ttf', uni=True)
78
- pdf.set_font('DejaVu', '', 12)
 
 
 
 
79
 
80
  # Title
81
  pdf.cell(200, 10, txt="Generated Document", ln=True, align="C")
 
1
  import streamlit as st
2
  from fpdf import FPDF
3
+ import os
4
 
5
  # Function to create various types of documents
6
  def generate_document(doc_type, text, style="formal"):
 
74
  pdf = FPDF()
75
  pdf.add_page()
76
 
77
+ # Check if DejaVu font exists, if not fallback to default
78
+ font_path = 'DejaVuSans.ttf'
79
+ if os.path.exists(font_path):
80
+ pdf.add_font('DejaVu', '', font_path, uni=True)
81
+ pdf.set_font('DejaVu', '', 12)
82
+ else:
83
+ pdf.set_font('Arial', '', 12) # Fallback font
84
 
85
  # Title
86
  pdf.cell(200, 10, txt="Generated Document", ln=True, align="C")