1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# ------- Dossier & Nom Fichier PDF Cible -------
Dossier_Cible = 'Recettes'
Nom_File = Nom_Rec.get()
# print("...........", Nom_File)
# Vérifie la présence du dossier cible
try:
os.makedirs(Dossier_Cible)
print("Le dossier --> ", Dossier_Cible, " est créé")
print("Vérification de l'existance du dossier ", os.path.isdir('./' + Dossier_Cible))
except FileExistsError:
print("Le dossier --> ", Dossier_Cible, " exite déjà")
print("Vérification de l'existance du dossier ", os.path.isdir('./' + Dossier_Cible))
# Identification du chemin de l'application
PathApp = os.getcwd()
print("Identification du chemin de l'application ", os.getcwd())
print("Full Path ", PathApp + "/" + Dossier_Cible + "/" + Nom_File + ".pdf")
# Attribution du chemin cible
# pdf = canvas.Canvas(PathApp + "/" + Dossier_Cible + "/" + Nom_File + ".pdf", pagesize=landscape(A4))
pdf = canvas.Canvas( "./" + Nom_File + ".pdf", pagesize=landscape(A4))
# # ------- Nom Recette -------
flow_Ligne1 = []
styles = getSampleStyleSheet()
stl_Recette_EU = ParagraphStyle(
name='Normal',
alignment=1,
fontName='Verdana-Bold',
fontSize=24,
textColor="#7E2300",
)
stl_Recette_TH = ParagraphStyle(
name='Normal',
alignment=1,
fontName='THSarabun-Bold',
fontSize=24,
textColor="#7E2300",
)
stl_Recette_AR = ParagraphStyle(
name='Normal',
alignment=1,
fontName='arabtype',
fontSize=24,
textColor="#7E2300",
)
# Vérification que la chaîne (Nom_File) ne contient que des caractères ASCII
NO_ASCII = ""
try:
New_Nom_File = Nom_File.encode('ascii')
flow_Ligne1.append(Paragraph(New_Nom_File, style=stl_Recette_EU))
except UnicodeEncodeError:
print("there are non-ascii characters in there")
NO_ASCII = "YES"
# Identification de la langue utilisée pour le titre de la recette puis orientation vers la bon style
if NO_ASCII == "YES":
# Méthode II
from langdetect import detect_langs
def ID_lang(Nom_File):
res = detect_langs(Nom_File)
for item in res:
if item.lang == "th" or item.lang == "ar":
return item.lang
return None
# print("-------------", ID_lang(string)) # fr
if ID_lang(Nom_File) == "th":
print("Thaïlandais", ID_lang(Nom_File))
Nom_File = Nom_File.encode('utf-8')
flow_Ligne1.append(Paragraph(Nom_File, style=stl_Recette_TH)) |
Partager