IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

auto-py-to-exe et reportlab


Sujet :

Python

  1. #1
    Invité
    Invité(e)
    Par défaut auto-py-to-exe et reportlab
    bonjour à tous,

    j'ai un fichier.py qui génère un PDF avec le module Reportlab qui fonctionne bien sous PyCharm

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
        # ===================
        #        --- Création PDF ---
        # ===================
        from reportlab.pdfgen import canvas
        from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.lib.units import mm
     
        # Format de la feuille
        from reportlab.lib.pagesizes import landscape
        from reportlab.lib.pagesizes import A4
     
        # Police Verdana
        from reportlab.pdfbase.pdfmetrics import registerFont
        from reportlab.pdfbase.ttfonts import TTFont
        registerFont(TTFont('Verdana', 'VERDANA.TTF'))
        registerFont(TTFont('Verdana-Bold', 'VERDANAB.TTF'))
        registerFont(TTFont('Verdana-Italic', 'VERDANAI.TTF'))
        registerFont(TTFont('Verdana-BoldItalic', 'VERDANAZ.TTF'))
     
        registerFont(TTFont('THSarabun', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-Bold', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-italic', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-BoldItalic', 'THSarabun.ttf'))
     
        registerFont(TTFont('arabtype', 'arabtype.ttf'))
     
        #
        from reportlab.lib import colors
    je contre un problème de non fonctionnement en voulant créer un éxecutable avec auto-py-toe-exe https://pypi.org/project/auto-py-to-exe/
    Nom : _40.jpg
Affichages : 975
Taille : 9,5 Ko

    j'ai testé en spécifier le chemin d'installation reportlab pour l'option "--additonal-hooks-dir-"
    C:\Users\master\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\reportlab

    de l'aide s'il vous plaît, merci de votre temps

  2. #2
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 462
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 462
    Points : 9 249
    Points
    9 249
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    "auto-py-to-exe" semble être une application graphique qui lance et exploite "pyinstaller". Ce qui est d'ailleurs une très bonne idée.

    Mais en cas de problème, on ne sait pas si ça vient du programme graphique ou de pyinstaller lui-même. Aussi, je suggère de travailler directement avec pyinstaller en console jusqu'à la solution (s'il y en a une).

    Par ailleurs, la recherche sous google de "pyinstaller reportlab" donne plusieurs sites qui parlent de problèmes. Et un bug est même cité chez reportlab, qui aurait été corrigé dans la version 3.4 (https://www.reportlab.com/documentat...n-reportlab-35): chercher "pyinstaller" dans la page, et voir si la version de reportlab utilisée est à moderniser.

    Ce que fait pyinstaller est complexe, et il faut souvent l'aider un peu. La consultation des lignes affichées pendant le traitement peut permettre de trouver une solution. On peut aussi essayer avec l'option "onedir" au lieu de "onefile", et voir dans les répertoires de traitement ce que pyinstaller a fait.
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

  3. #3
    Invité
    Invité(e)
    Par défaut
    la version installée est : C:\Users\master\AppData\Local\Programs\Python\Python37-32\python.exe C:/!TEST!/py/PDF/ReportLab/Version_ReportLab_3.5.42.py --> 3.5.42

    j'ai fait une avec ce code que j'ai trouvé sur le net - La moulinette fonctionne bien en mode onefile
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import letter
    from reportlab.lib.units import mm
    if __name__ == '__main__':
    	name = u'Mr. John Doe'
    	city = 'Pereira'
    	address = 'ELM Street'
    	phone = '555-7241'
    	c = canvas.Canvas(filename='invoice.pdf', pagesize= (letter[0], letter[1]/2))
    	c.setFont('Helvetica', 10)
    	# Print Customer Data
    	c.drawString(107*mm, 120*mm, name)
    	c.drawString(107*mm, 111*mm, city)
    	c.drawString(107*mm, 106*mm, address)
    	c.drawString(107*mm, 101*mm, phone)
    	# c.showPage()
    	c.save()
    ce qui diffère avec mon code est la police de caractères

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
        from reportlab.pdfgen import canvas
        from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.lib.units import mm
     
        # Format de la feuille
        from reportlab.lib.pagesizes import landscape
        from reportlab.lib.pagesizes import A4
     
        # Police Verdana
        from reportlab.pdfbase.pdfmetrics import registerFont
        from reportlab.pdfbase.ttfonts import TTFont
        registerFont(TTFont('Verdana', 'VERDANA.TTF'))
        registerFont(TTFont('Verdana-Bold', 'VERDANAB.TTF'))
        registerFont(TTFont('Verdana-Italic', 'VERDANAI.TTF'))
        registerFont(TTFont('Verdana-BoldItalic', 'VERDANAZ.TTF'))
     
        registerFont(TTFont('THSarabun', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-Bold', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-italic', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-BoldItalic', 'THSarabun.ttf'))
     
        registerFont(TTFont('arabtype', 'arabtype.ttf'))
     
        #
        from reportlab.lib import colors
    comment encapsuler les polices TTF, svp?
    merci de votre temps
    Dernière modification par Invité ; 23/07/2020 à 09h10.

  4. #4
    Invité
    Invité(e)
    Par défaut
    voici le résultat de la compilation
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
     
    Running auto-py-to-exe v2.7.5
    Building directory: C:\Users\master\AppData\Local\Temp\tmpd4nrc67y
    Provided command: pyinstaller --noconfirm --onefile --windowed --icon "C:/!TEST!/_TEST_/Compile_5/ICO/Soap_0.ico" --add-data "C:/!TEST!/_TEST_/Compile_5/ICO;.ICO/" --add-data "C:/!TEST!/_TEST_/Compile_5/DOC;.DOC/" --add-data "C:/!TEST!/_TEST_/Compile_5/DB;.DB/" --add-data "C:/!TEST!/_TEST_/Compile_5/TTF;.TTF/" --add-data "C:/!TEST!/_TEST_/Compile_5/Recettes;.Recettes/" --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/AE.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/AG.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/ALC.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/AO.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/ARG.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/Divers.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/FRAG.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/HE.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/HV.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/Recettes.db;." --add-binary "C:/!TEST!/_TEST_/Compile_5/DB/TT.db;." --hidden-import "pkg_resources.py2_warn" --additional-hooks-dir "C:/!TEST!/_TEST_/Compile_5/DB" --additional-hooks-dir "C:/!TEST!/_TEST_/Compile_5/TTF" --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/arabtype.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Bold Italic.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Bold.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Italic.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/verdana.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/verdanab.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/verdanai.ttf;." --add-binary "C:/!TEST!/_TEST_/Compile_5/TTF/verdanaz.ttf;."  "C:/!TEST!/_TEST_/Compile_5/Main.py"
    Recursion Limit is set to 5000
    Executing: pyinstaller --noconfirm --onefile --windowed --icon C:/!TEST!/_TEST_/Compile_5/ICO/Soap_0.ico --add-data C:/!TEST!/_TEST_/Compile_5/ICO;.ICO/ --add-data C:/!TEST!/_TEST_/Compile_5/DOC;.DOC/ --add-data C:/!TEST!/_TEST_/Compile_5/DB;.DB/ --add-data C:/!TEST!/_TEST_/Compile_5/TTF;.TTF/ --add-data C:/!TEST!/_TEST_/Compile_5/Recettes;.Recettes/ --add-binary C:/!TEST!/_TEST_/Compile_5/DB/AE.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/AG.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/ALC.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/AO.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/ARG.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/Divers.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/FRAG.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/HE.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/HV.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/Recettes.db;. --add-binary C:/!TEST!/_TEST_/Compile_5/DB/TT.db;. --hidden-import pkg_resources.py2_warn --additional-hooks-dir C:/!TEST!/_TEST_/Compile_5/DB --additional-hooks-dir C:/!TEST!/_TEST_/Compile_5/TTF --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/arabtype.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Bold Italic.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Bold.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun Italic.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/THSarabun.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/verdana.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/verdanab.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/verdanai.ttf;. --add-binary C:/!TEST!/_TEST_/Compile_5/TTF/verdanaz.ttf;. C:/!TEST!/_TEST_/Compile_5/Main.py --distpath C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\application --workpath C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build --specpath C:\Users\master\AppData\Local\Temp\tmpd4nrc67y
     
    2244367 INFO: PyInstaller: 3.6
    2244371 INFO: Python: 3.7.2
    2244376 INFO: Platform: Windows-7-6.1.7601-SP1
    2244381 INFO: wrote C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\Main.spec
    2244389 INFO: UPX is not available.
    2244394 INFO: Extending PYTHONPATH with paths
    ['C:\\!TEST!\\_TEST_\\Compile_5',
     'C:\\Users\\master\\AppData\\Local\\Temp\\tmpd4nrc67y']
    2244401 INFO: checking Analysis
    2244406 INFO: Building Analysis because Analysis-03.toc is non existent
    2244410 INFO: Reusing cached module dependency graph...
    2244449 INFO: Caching module graph hooks...
    2244501 INFO: running Analysis Analysis-03.toc
    2244507 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
      required by c:\users\master\appdata\local\programs\python\python37-32\python.exe
    2244740 INFO: Analyzing C:\!TEST!\_TEST_\Compile_5\Main.py
    2245209 INFO: Processing pre-safe import module hook   six.moves
    2246063 INFO: Processing pre-find module path hook   distutils
    2246068 INFO: distutils: retargeting to non-venv dir 'c:\\users\\master\\appdata\\local\\programs\\python\\python37-32\\lib'
    2247885 INFO: Processing pre-find module path hook   site
    2247890 INFO: site: retargeting to fake-dir 'c:\\users\\master\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\PyInstaller\\fake-modules'
    2249008 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
    2252632 INFO: Analyzing hidden import 'pkg_resources.py2_warn'
    2252638 INFO: Processing module hooks...
    2252644 INFO: Loading module hook "hook-distutils.py"...
    2252649 INFO: Loading module hook "hook-encodings.py"...
    2252733 INFO: Loading module hook "hook-gevent.py"...
    2252918 WARNING: Unable to find package for requirement greenlet from package gevent.
    2252923 INFO: Packages required by gevent:
    ['cffi']
    2254022 INFO: Loading module hook "hook-lib2to3.py"...
    2254031 INFO: Loading module hook "hook-numpy.core.py"...
    2254035 INFO: Loading module hook "hook-numpy.py"...
    2254039 INFO: Loading module hook "hook-PIL.Image.py"...
    2254289 INFO: Loading module hook "hook-PIL.py"...
    2254296 INFO: Excluding import 'PyQt5'
    2254302 INFO:   Removing import of PyQt5 from module PIL.ImageQt
    2254305 INFO: Excluding import 'tkinter'
    2254311 INFO:   Removing import of tkinter from module PIL.ImageTk
    2254315 INFO: Import to be excluded not found: 'FixTk'
    2254320 INFO: Import to be excluded not found: 'PySide'
    2254325 INFO: Import to be excluded not found: 'PyQt4'
    2254328 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
    2254338 INFO: Import to be excluded not found: 'FixTk'
    2254343 INFO: Excluding import 'tkinter'
    2254347 INFO: Loading module hook "hook-pkg_resources.py"...
    2254634 INFO: Processing pre-safe import module hook   win32com
    2254842 INFO: Excluding import '__main__'
    2254850 INFO:   Removing import of __main__ from module pkg_resources
    2254855 INFO: Loading module hook "hook-pycparser.py"...
    2254859 INFO: Loading module hook "hook-pydoc.py"...
    2254863 INFO: Loading module hook "hook-pythoncom.py"...
    2255145 INFO: Loading module hook "hook-pywintypes.py"...
    2255420 INFO: Loading module hook "hook-reportlab.lib.utils.py"...
    2255428 INFO: Loading module hook "hook-reportlab.pdfbase._fontdata.py"...
    2255509 INFO: Loading module hook "hook-setuptools.py"...
    2255952 INFO: Loading module hook "hook-sqlite3.py"...
    2256039 INFO: Loading module hook "hook-sysconfig.py"...
    2256045 INFO: Loading module hook "hook-win32com.py"...
    2256324 INFO: Loading module hook "hook-xml.dom.domreg.py"...
    2256329 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
    2256336 INFO: Loading module hook "hook-xml.py"...
    2256342 INFO: Loading module hook "hook-_tkinter.py"...
    2256478 INFO: checking Tree
    2256485 INFO: Building Tree because Tree-06.toc is non existent
    2256490 INFO: Building Tree Tree-06.toc
    2256565 INFO: checking Tree
    2256572 INFO: Building Tree because Tree-07.toc is non existent
    2256579 INFO: Building Tree Tree-07.toc
    2256645 INFO: Looking for ctypes DLLs
    2256717 INFO: Analyzing run-time hooks ...
    2256727 INFO: Including run-time hook 'pyi_rth_pkgres.py'
    2256732 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
    2256740 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
    2256747 INFO: Including run-time hook 'pyi_rth__tkinter.py'
    2256761 INFO: Looking for dynamic libraries
    2257258 INFO: Looking for eggs
    2257266 INFO: Using Python library c:\users\master\appdata\local\programs\python\python37-32\python37.dll
    2257273 INFO: Found binding redirects: 
    []
    2257286 INFO: Warnings written to C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build\Main\warn-Main.txt
    2257413 INFO: Graph cross-reference written to C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build\Main\xref-Main.html
    2257472 INFO: Appending 'binaries' from .spec
    2257480 INFO: Appending 'datas' from .spec
    2257492 INFO: checking PYZ
    2257496 INFO: Building PYZ because PYZ-03.toc is non existent
    2257503 INFO: Building PYZ (ZlibArchive) C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build\Main\PYZ-03.pyz
    2259166 INFO: Building PYZ (ZlibArchive) C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build\Main\PYZ-03.pyz completed successfully.
    2259197 INFO: checking PKG
    2259203 INFO: Building PKG because PKG-03.toc is non existent
    2259207 INFO: Building PKG (CArchive) PKG-03.pkg
    2265269 INFO: Building PKG (CArchive) PKG-03.pkg completed successfully.
    2265304 INFO: Bootloader c:\users\master\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
    2265310 INFO: checking EXE
    2265314 INFO: Building EXE because EXE-03.toc is non existent
    2265323 INFO: Building EXE from EXE-03.toc
    2265329 INFO: Copying icons from ['C:\\!TEST!\\_TEST_\\Compile_5\\ICO\\Soap_0.ico']
    2265337 INFO: Writing RT_GROUP_ICON 0 resource with 48 bytes
    2265341 INFO: Writing RT_ICON 1 resource with 1128 bytes
    2265347 INFO: Writing RT_ICON 2 resource with 4264 bytes
    2265353 INFO: Writing RT_ICON 3 resource with 9640 bytes
    2265361 INFO: Updating manifest in C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\build\Main\runw.exe._jn54jjk
    2265366 INFO: Updating resource type 24 name 1 language 0
    2265375 INFO: Appending archive to EXE C:\Users\master\AppData\Local\Temp\tmpd4nrc67y\application\Main.exe
    2265400 INFO: Building EXE from EXE-03.toc completed successfully.
     
    Moving project to: C:\!TEST!\_TEST_\Compile_5\output
    Complete.

  5. #5
    Invité
    Invité(e)
    Par défaut
    j'ai testé avec l'option One-directory et Debug ALL de Auto-py-to-exe et j'obtiens
    Nom : _40.jpg
Affichages : 960
Taille : 9,5 Ko

    je ne sais vraiment ce que je fais, c'est nouveau pour moi
    comment puis obtenir un rapport d'erreur de compilation?
    merci

  6. #6
    Invité
    Invité(e)
    Par défaut
    après multiple test afin de trouver la source du problème, ces lignes sont la cause du problème

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
        # from reportlab.pdfbase.pdfmetrics import registerFont
        # from reportlab.pdfbase.ttfonts import TTFont
        # registerFont(TTFont('Verdana', 'VERDANA.TTF'))
        # registerFont(TTFont('Verdana-Bold', 'VERDANAB.TTF'))
        # registerFont(TTFont('Verdana-Italic', 'VERDANAI.TTF'))
        # registerFont(TTFont('Verdana-BoldItalic', 'VERDANAZ.TTF'))
        #
        # registerFont(TTFont('THSarabun', 'THSarabun.ttf'))
        # registerFont(TTFont('THSarabun-Bold', 'THSarabun.ttf'))
        # registerFont(TTFont('THSarabun-italic', 'THSarabun.ttf'))
        # registerFont(TTFont('THSarabun-BoldItalic', 'THSarabun.ttf'))
     
        # registerFont(TTFont('arabtype', 'arabtype.ttf'))
    en configurant le style de paragraphe avec une police propre à reportlab
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
        st_Titre = ParagraphStyle(
            name='Normal',
            fontName='Helvetica',
            fontSize=8,
            textColor='blue'
        )
    la compilation fonctionne.

    comment puis configurer pyinstaller avec des polices TTF externe à reportlab?
    merci votre aide

  7. #7
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 462
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 462
    Points : 9 249
    Points
    9 249
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    Le problème, c'est que je ne connais pas du tout reportlab. Mais comme je suis curieux, j'ai cherché. Et comme vous ne donnez pas un code de test complet, j'en ai cherché un pour faire des essais.

    J'ai trouvé un petit code qui fabrique un petit pdf avec intégration de polices de caractères ici:
    https://www.reportlab.com/documentation/faq/#2.6

    Voilà ce code que j'ai appelé "test01.pyw":

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    import os
    import reportlab
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfgen.canvas import Canvas
    folder = os.path.dirname(reportlab.__file__) + os.sep + 'fonts'
    afmFile = os.path.join(folder, 'DarkGardenMK.afm')
    pfbFile = os.path.join(folder, 'DarkGardenMK.pfb')
    ttfFile = os.path.join(folder, 'Vera.ttf')
    justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
    faceName = 'DarkGardenMK' # pulled from AFM file
    pdfmetrics.registerTypeFace(justFace)
    justFont = pdfmetrics.Font('DarkGardenMK', faceName, 'WinAnsiEncoding')
    pdfmetrics.registerFont(justFont)
    pdfmetrics.registerFont(TTFont("Vera", ttfFile))
    canvas = Canvas('TestFonts.pdf')
    canvas.setFont('DarkGardenMK', 32)
    canvas.drawString(10, 150, 'This should be drawn in')
    canvas.drawString(10, 100, 'the font DarkGardenMK')
    canvas.setFont('Vera', 32)
    canvas.drawString(10, 250, 'This should be drawn in')
    canvas.drawString(10, 200, 'the font Vera')
    canvas.showPage()
    canvas.save()
    Ce code fonctionne, et crée dans le répertoire du programme le fichier pdf "TestFonts.pdf".

    Alors, je le traite par pyinstaller avec le script bat suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    IF EXIST build RMDIR /S /Q build
    IF EXIST dist RMDIR /S /Q dist
     
    pyinstaller.exe ^
    --clean ^
    --noconfirm ^
    --noconsole ^
    --onedir ^
    --noupx ^
    test01.pyw
    PAUSE
    Et lorsque j'exécute le fichier "test01.exe", j’obtiens la même erreur fatale que vous!

    Alors, je fais afficher la variable "folder", et je constate qu'elle fait partie du reportlab installé dans le python normal, chez moi: "E:\Programmes\Python37\lib\site-packages\reportlab\fonts".
    Et c'est là que ça ne va pas: le programme exe doit travailler avec l'interpréteur et les modules embarqués (dont reportlab), et non avec le Python installé "normal"! Et pour intégrer des fichiers de données "non-python", le répertoire doit être ajusté entre la version ".py" et la version ".exe".

    Heureusement, ça se soigne! Et c'est dans la notice de pyinstaller (https://pyinstaller.readthedocs.io/e...formation.html)

    Voilà comment faire:

    - d'abord, faire en sorte que le contenu du répertoire "....\site-packages\reportlab\fonts" soit recopié dans un sous-répertoire "fonts" du répertoire cible pendant le traitement par pyinstaller. On ajoute simplement la ligne suivante dans le script ".bat" (mettre le bon chemin):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    --add-data "E:\Programmes\Python37\Lib\site-packages\reportlab\fonts;fonts" ^
    - puis, modifier le code du programme de la façon suivante:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import sys # <= ajout
     
    import os
    import reportlab
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfgen.canvas import Canvas
     
    # modif du calcul du chemin du répertoire "fonts"
    if getattr(sys, 'frozen', False):
        folder = os.path.join(sys._MEIPASS, "fonts") # programma traité par pyinstaller
    else:
        folder = os.path.join(os.path.dirname(reportlab.__file__), 'fonts') # programme non traité
     
    afmFile = os.path.join(folder, 'DarkGardenMK.afm')
    pfbFile = os.path.join(folder, 'DarkGardenMK.pfb')
    ttfFile = os.path.join(folder, 'Vera.ttf')
    justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
    faceName = 'DarkGardenMK' # pulled from AFM file
    pdfmetrics.registerTypeFace(justFace)
    justFont = pdfmetrics.Font('DarkGardenMK', faceName, 'WinAnsiEncoding')
    pdfmetrics.registerFont(justFont)
    pdfmetrics.registerFont(TTFont("Vera", ttfFile))
    canvas = Canvas('TestFonts.pdf')
    canvas.setFont('DarkGardenMK', 32)
    canvas.drawString(10, 150, 'This should be drawn in')
    canvas.drawString(10, 100, 'the font DarkGardenMK')
    canvas.setFont('Vera', 32)
    canvas.drawString(10, 250, 'This should be drawn in')
    canvas.drawString(10, 200, 'the font Vera')
    canvas.showPage()
    canvas.save()
    Et là, ça marche dans les 2 cas: exécution du ".py" et du ".exe".

    A noter que la version "onefile" fonctionne aussi pour les même raisons.

    Rappelons que la version "onefile" fabrique un exe seul, ce qui facilite la distribution, mais l'exe en question n'est qu'une archive exécutable, et au lancement, le fichier exe se désarchive dans un répertoire temporaire, et c'est là qu'il s'exécute. A part cette partie "désarchivage", c'est le même fonctionnement que la version "onedir". En tout cas, ce n'est pas une "compilation" en code natif, mais une encapsulation du code python avec l'interpréteur python et tous les modules et données nécessaires.

    A vous de voir comment adapter ça à votre propre code.
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

  8. #8
    Invité
    Invité(e)
    Par défaut
    merci pour votre temps et investigations.

    je n'utilise pas les polices propre à Reportlab
    j'ai aussi creusé le problème en ayant les fichiers TTF dans le projet [Fonts] ex : verdana.ttf -- THSarabun.ttf -- arabtype.ttf

    voici le code entier de la page générant le pdf

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
     
    # coding:utf-8
    #version 3.x python
    # ---------------------------------------------------------
    #                                 Modules
    # ---------------------------------------------------------
    import sys
    import os.path
    from os import path
    # import psutil
    # import subprocess
    # from subprocess import check_output
    from tkinter import *
    from tkinter.ttk import *
    # import datetime
    from langdetect import detect                                                                             # Détecte la langue d'un texte, d'une variable string
     
    import PDF
     
    def TABLES(Liste_Full, Liste_Somme, Liste_Indices_Finaux, Nom_Rec, Liste_Ajouts1, Liste_Ajouts2, Liste_Ajouts3, Liste_Ajouts4, Liste_Ajouts5, Liste_Ajouts6, Liste_Ajouts7, Liste_Ajouts8, Qt_TT_Recette, prix):
        print("\n" + "<--- Liste des information nécessaire pour le PDF_Build --->")
        print("<--->	Nom_Recette				", Nom_Rec.get())
        print("<--->	Liste_Full					", Liste_Full)
        print("<--->	Liste_Somme				", Liste_Somme)
        print("<--->	Liste_Indices_Finaux	", Liste_Indices_Finaux)
        print("<--->	Liste_Ajouts1				", Liste_Ajouts1)
        print("<--->	Liste_Ajouts2				", Liste_Ajouts2)
        print("<--->	Liste_Ajouts3				", Liste_Ajouts3)
        print("<--->	Liste_Ajouts4				", Liste_Ajouts4)
        print("<--->	Liste_Ajouts5				", Liste_Ajouts5)
        print("<--->	Liste_Ajouts6				", Liste_Ajouts6)
        print("<--->	Liste_Ajouts7				", Liste_Ajouts7)
        print("<--->	Liste_Ajouts8				", Liste_Ajouts8)
        print("<--->	Poids Recette				", Qt_TT_Recette)
        print("<--->	Prix Recette				", prix)
        print("\n")
     
        # Référence les HV sans Prix
        HV_NoPrix = []
        HV_NoPrix[:] = []
        for u in range(0, len(Liste_Full)):
            # print("HV", Liste_Full[u][0], "        Prix", Liste_Full[u][24])
            if Liste_Full[u][24] == 0:
                HV_NoPrix.append(Liste_Full[u][0])
        # print("HV_NoPrix - Huile sans prix", HV_NoPrix)                                                # ex : ['Babassu', 'Arachide', 'Amande douce']
        Liste_HV_wo_Price = StringVar()
        Liste_HV_wo_Price = ""
        for u in range(0, len(HV_NoPrix)):
            Liste_HV_wo_Price = Liste_HV_wo_Price + "               " + HV_NoPrix[u]
        # print("Liste_HV_wo_Price", Liste_HV_wo_Price)
        HV_NoPrix[:] = []
     
        # Encapsulation des Liste_AjoutsX dans Listes_Ajouts_Full
        # Enregistre le nombre d'éléments de chaque Liste_AjoutsX
        Compteur = 0                                                                                               # Compteur le Nb de Liste_AjoutsX non vide
        Elements = []                                                                                                # Contient le Nb Items de chaque Liste_AjoutsX
        Element_Ligne1 =[]                                                                                       # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 1
        Element_Ligne2 = []                                                                                      # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 2
        Listes_Ajouts_Full =[]
        if len(Liste_Ajouts1) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts1)
            # print("Listes_Ajouts_Full - Liste_Ajouts1", Listes_Ajouts_Full)
            if len(Liste_Ajouts1) > 0:
                Elements.append(len(Liste_Ajouts1))
                Compteur = Compteur + 1
        if len(Liste_Ajouts2) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts2)
            # print("Listes_Ajouts_Full - Liste_Ajouts2", Listes_Ajouts_Full)
            if len(Liste_Ajouts2) > 0:
                Elements.append(len(Liste_Ajouts2))
                Compteur = Compteur + 1
        if len(Liste_Ajouts3) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts3)
            # print("Listes_Ajouts_Full - Liste_Ajouts3", Listes_Ajouts_Full)
            if len(Liste_Ajouts3) > 0:
                Elements.append(len(Liste_Ajouts3))
                Compteur = Compteur + 1
        if len(Liste_Ajouts4) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts4)
            # print("Listes_Ajouts_Full - Liste_Ajouts4", Listes_Ajouts_Full)
            if len(Liste_Ajouts4) > 0:
                Elements.append(len(Liste_Ajouts4))
                Compteur = Compteur + 1
        if len(Liste_Ajouts5) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts5)
            # print("Listes_Ajouts_Full - Liste_Ajouts5", Listes_Ajouts_Full)
            if len(Liste_Ajouts5) > 0:
                Elements.append(len(Liste_Ajouts5))
                Compteur = Compteur + 1
        if len(Liste_Ajouts6) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts6)
            # print("Listes_Ajouts_Full - Liste_Ajouts6", Listes_Ajouts_Full)
            if len(Liste_Ajouts6) > 0:
                Elements.append(len(Liste_Ajouts6))
                Compteur = Compteur + 1
        if len(Liste_Ajouts7) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts7)
            # print("Listes_Ajouts_Full - Liste_Ajouts7", Listes_Ajouts_Full)
            if len(Liste_Ajouts7) > 0:
                Elements.append(len(Liste_Ajouts7))
                Compteur = Compteur + 1
        if len(Liste_Ajouts8) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts8)
            # print("Listes_Ajouts_Full - Liste_Ajouts8", Listes_Ajouts_Full)
            if len(Liste_Ajouts8) > 0:
                Elements.append(len(Liste_Ajouts8))
                Compteur = Compteur + 1
     
        # print("len(Listes_Ajouts_Full) -- Listes_Ajouts_Full", len(Listes_Ajouts_Full), "       ", Listes_Ajouts_Full)
        # for u in range(0, len(Listes_Ajouts_Full)):
        #     for z in range(0, len(Listes_Ajouts_Full[u])):
                # print("Listes_Ajouts_Full[", u, "][", z, "]", Listes_Ajouts_Full[u][z])
     
        # Regroupe le Nb Item par tranche de 4 colonnes pour chaque ligne d'affichage
        # print("Elements", Elements)
        # print("Compteur", Compteur)
        if len(Elements) <= 4:
            for i in range(0, Compteur):
                Element_Ligne1.append(Elements[i])
            # print("Element_Ligne1 -- <= 4", Element_Ligne1)
            max_Ligne1 = IntVar()
            if Element_Ligne1 == []:
                max_Ligne1 = 0
            if Element_Ligne1 != []:
                max_Ligne1 = max(Element_Ligne1) - 1
                # print("max_Ligne1", max_Ligne1)
     
        if len(Elements) >= 4:
            for i in range(0, 4):
                Element_Ligne1.append(Elements[i])
            # print("Element_Ligne1 -- >= 4", Element_Ligne1)
            max_Ligne1 = IntVar()
            max_Ligne1 = max(Element_Ligne1) - 1
            # print("max_Ligne1", max_Ligne1)
            Solde_Compteur = Compteur - (Compteur - 4)
            # print("Solde_Compteur", Solde_Compteur)
     
            for j in range(Solde_Compteur, Compteur):
                Element_Ligne2.append(Elements[j])
            # print("Element_Ligne2 -- >= 4", Element_Ligne2)
            max_Ligne2 = IntVar()
            if Element_Ligne2 == []:
                max_Ligne2 = 0
            if Element_Ligne2 != []:
                max_Ligne2 = max(Element_Ligne2) - 1
                # print("max_Ligne2", max_Ligne2)
     
        # ===================
        #        --- Création PDF ---
        # ===================
        import reportlab
        from reportlab.pdfgen import canvas
        from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.lib.units import mm
     
        # Format de la feuille
        from reportlab.lib.pagesizes import landscape
        from reportlab.lib.pagesizes import A4
     
        # Police Verdana
        from reportlab.pdfbase.pdfmetrics import registerFont
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont
        from reportlab import rl_config
     
        rl_config.TTFSearchPath.append('C:/!TEST!/_TEST_/Fonts')
     
        registerFont(TTFont('Verdana', 'VERDANA.TTF'))
        registerFont(TTFont('Verdana-Bold', 'VERDANAB.TTF'))
        registerFont(TTFont('Verdana-Italic', 'VERDANAI.TTF'))
        registerFont(TTFont('Verdana-BoldItalic', 'VERDANAZ.TTF'))
     
        registerFont(TTFont('THSarabun', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-Bold', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-italic', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-BoldItalic', 'THSarabun.ttf'))
     
        registerFont(TTFont('arabtype', 'arabtype.TTF'))
        #
        from reportlab.lib import colors
     
        # ===================
        # ------- Styles TitreX_X -------
        # ===================
        # alignmemt -- Valeur :  0 Gauche -- 1 Centrer -- 2 Droite --
        st_Titre = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='blue'
        )
        st_Titre_Ajouts = ParagraphStyle(
            name='Normal',
            alignment=0,
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='blue'
        )
     
        # ===============================
        # ------- Nom Fichier Cible PDF & Titre PAGE -------
        # ===============================
        # Identifie PID du processus ...
        os.system("tasklist | findstr /I Acrobat.exe")
        os.system("tasklist | findstr /I AcroRd32.exe")
        # Tue le processus ...
        os.system("taskkill /f /im Acrobat.exe")                                                           # Acrobat Reader
        os.system("taskkill /f /im AcroRd32.exe")                                                         # Acrobat Reader
     
        # ------- Dossier Cible & Nom fichier PDF -------
        Dossier_Cible = 'Recettes'
        Nom_File = Nom_Rec.get() + ".pdf"
     
        # Vérifie la présence du dossier cible
        try:
            os.makedirs(Dossier_Cible)
            print("Directory    " , Dossier_Cible ,  " Created ")
        except FileExistsError:
            print("Directory    " , Dossier_Cible ,  " already exists")
     
        # Ecriture du fichier cible
        pdf = canvas.Canvas(Dossier_Cible + "/" + Nom_File, 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",
        )
        # Identification de la langue utilisée pour le titre de la recette puis orientation vers la bon style
        Titre_Recette = ""
        lang_Nom_Rec = detect(Nom_Rec.get())                                                          # detect la langue utilisée pour le titre
        # print("lang_Nom_Rec", lang_Nom_Rec, type(lang_Nom_Rec))
        if lang_Nom_Rec == "it":
            Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_EU)
        if lang_Nom_Rec == "th":
            Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_TH)
        if lang_Nom_Rec == "ar":
            Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_AR)
     
        flow_Ligne1.append(Titre_Recette)
     
        frame = Frame(20, 540, 800, 30, showBoundary=0)
        frame.addFromList(flow_Ligne1, pdf)
     
        # ===============
        # ------- Colonne 1 -------
        # ===============
        flow_Col1 = []
     
        # ------- Ligne 1 -------
        Titre1_1 = Paragraph("Huiles - gr.", style=st_Titre)
        flow_Col1.append(Titre1_1)
     
        # ------- Ligne 2 -------
        # # Nom HV
        HV_Nom = []
        HV_Nom = [[u[0]] for u in Liste_Full]
        tb_HVNom = Table(HV_Nom, len(HV_Nom) * [45 * mm], len(HV_Nom) * [5 * mm])
        # # Qt HV
        HV_Qt = []
        HV_Qt = [[u[2]] for u in Liste_Full]
        tb_HVQt = Table(HV_Qt, len(HV_Qt) * [15 * mm], len(HV_Qt) * [5 * mm])
     
        Ligne2_Col1 = Table([[tb_HVNom, tb_HVQt]], [140,50])
     
        st_L2C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Ligne2_Col1.setStyle(st_L2C1)
        flow_Col1.append(Ligne2_Col1)
     
        # ------- Ligne 3 -------
        Titre1_2 = Paragraph("<br/>" + "Hydroxyde de sodium & H2O - gr.", style=st_Titre)
        flow_Col1.append(Titre1_2)
     
        # ------- Ligne 4 -------
        # # SC TT Qt
        TxT_SC_TT_Qt = []
        TxT_SC_TT_Qt = [['Soude Caustique - NaOH']]
        TxTSC_TT_Qt = Table(TxT_SC_TT_Qt)
        SC_TT_Qt = []
        SC_TT_Qt = [[Liste_Indices_Finaux[2]]]
        SCTT_Qt = Table(SC_TT_Qt)
     
        # # Eau TT Qt
        TxT_H2O_TT_Qt = []
        TxT_H2O_TT_Qt = [['Eau distillée']]
        TxTH2O_TT_Qt = Table(TxT_H2O_TT_Qt)
        H2O_TT_Qt = []
        H2O_TT_Qt = [[Liste_Indices_Finaux[3]]]
        H2OTT_Qt = Table(H2O_TT_Qt)
     
        Ligne4_Col1 = Table([[TxTSC_TT_Qt, SCTT_Qt], [TxTH2O_TT_Qt, H2OTT_Qt]], [140,50])
        #
        st_L4C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne4_Col1.setStyle(st_L4C1)
        flow_Col1.append(Ligne4_Col1)
     
        # ------- Ligne 5 -------
        Titre1_3 = Paragraph("<br/>" + "Réduction & Concentration", style=st_Titre)
        flow_Col1.append(Titre1_3)
     
        # ------- Ligne 6 -------
        # # Réduction de soude caustique
        TxT_Reduc_Soude = []
        TxT_Reduc_Soude = [['Réduction soude caustique']]
        TxTReducSoude = Table(TxT_Reduc_Soude)
        Reduc_Soude_Qt = []
        Reduc_Soude_Qt = [[Liste_Indices_Finaux[0]]]
        ReducSoudeQt = Table(Reduc_Soude_Qt)
     
        # # Concentration Lessive
        TxT_Concentration_Lessive = []
        TxT_Concentration_Lessive = [['Concentration Lessive']]
        TxTConcentrationLessive = Table(TxT_Concentration_Lessive)
        Concentration_Lessive_Qt = []
        Concentration_Lessive_Qt = [[Liste_Indices_Finaux[1]]]
        ConcentrationLessiveQt = Table(Concentration_Lessive_Qt)
     
        Ligne6_Col1 = Table([[TxTReducSoude, ReducSoudeQt], [TxTConcentrationLessive, ConcentrationLessiveQt]], [140,50])
        #
        st_L6C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne6_Col1.setStyle(st_L6C1)
        flow_Col1.append(Ligne6_Col1)
     
        frame = Frame(20, 330, 190, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col1, pdf)
     
        # ===============
        # ------- Colonne 2 -------
        # ===============
        flow_Col2 = []
     
        # ------- Ligne 1 -------
        Titre2_1 = Paragraph("Poids - gr.", style=st_Titre)
        flow_Col2.append(Titre2_1)
     
        # ------- Ligne 2 -------
        # # HV TT Qt
        TxT_HV_TT_Qt = []
        TxT_HV_TT_Qt = [['Huiles']]
        TxTHVTTQt = Table(TxT_HV_TT_Qt)
        HV_TT_Qt = []
        HV_TT_Qt = [[Liste_Somme[0]]]
        HVTTQt = Table(HV_TT_Qt)
     
        # # Qt TT Recette
        TxT_Rec_TT_Qt = []
        TxT_Rec_TT_Qt = [['Recette']]
        TxTTT_Qt = Table(TxT_Rec_TT_Qt, [133])
        Rec_TT_Qt = []
        Rec_TT_Qt = [[Qt_TT_Recette]]
        RecTT_Qt = Table(Rec_TT_Qt, [33])
     
        Ligne1_Col2 = Table([[TxTHVTTQt, HVTTQt], [TxTTT_Qt, RecTT_Qt]], [105,55])
        #
        st_L1C2 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne1_Col2.setStyle(st_L1C2)
        flow_Col2.append(Ligne1_Col2)
     
        # ------- Ligne 3 -------
        st_Red = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='red'
        )
     
        flow_Prix = []
        Titre2_2 = Paragraph("<br/>" +"Coût de revient", style=st_Titre)
        Titre2_2a = Paragraph("(*)", style=st_Red)
        Titre2_final = Table([[Titre2_2, Titre2_2a]], [90, 80])
        flow_Col2.append(Titre2_final)
     
        # ------- Ligne 4 -------
        # # HV Prix
        TxT_HV_Prix = []
        TxT_HV_Prix = [['Recette']]
        TxTHVPrix = Table(TxT_HV_Prix)
        HV_Prix = []
        HV_Prix = [[prix]]
        HVPrix = Table(HV_Prix)
     
        Ligne2_Col2 = Table([[TxTHVPrix, HVPrix]], [105,55])
        #
        st_L2C2 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne2_Col2.setStyle(st_L2C2)
        flow_Col2.append(Ligne2_Col2)
     
        # ------- Ligne 5 -------
        DateStart = Paragraph("<br/>" + "Date de création", style=st_Titre)
        flow_Col2.append(DateStart)
        Cure = Paragraph("<br/>" + "Temps de séquestration", style=st_Titre)
        flow_Col2.append(Cure)
        Ph = Paragraph("<br/>" + "Mesure Ph", style=st_Titre)
        flow_Col2.append(Ph)
     
        frame = Frame(226.67, 330, 160, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col2, pdf)
     
        # ===============
        # ------- Colonne 3 -------
        # ===============
        flow_Col3 = []
     
        # ------- Ligne 1 -------
        Titre3_1 = Paragraph("Propriétés du savon", style=st_Titre)
        flow_Col3.append(Titre3_1)
     
        # ------- Ligne 2 -------
        # Indice Dureté
        TxT_Durete = []
        TxT_Durete = [['Dureté']]
        TxTDurete = Table(TxT_Durete)
        Durete_val = []
        Durete_val = [[Liste_Indices_Finaux[6]]]
        Dureteval = Table(Durete_val)
        # Indice Détergent
        TxT_Detergent = []
        TxT_Detergent = [['Détergent']]
        TxTDetergent = Table(TxT_Detergent)
        Detergent_val = []
        Detergent_val = [[Liste_Indices_Finaux[7]]]
        Detergentval = Table(Detergent_val)
        # Indice Hydratation
        TxT_Hydratation = []
        TxT_Hydratation = [['Hydratation']]
        TxTHydratation = Table(TxT_Hydratation)
        Hydratation_val = []
        Hydratation_val = [[Liste_Indices_Finaux[8]]]
        Hydratationval = Table(Hydratation_val)
        # Indice Moussant
        TxT_Moussant = []
        TxT_Moussant = [['Moussant']]
        TxTMoussant = Table(TxT_Moussant)
        Moussant_val = []
        Moussant_val = [[Liste_Indices_Finaux[9]]]
        Moussantval = Table(Moussant_val)
        # Indice QMousse
        TxT_QMousse = []
        TxT_QMousse = [['Qualité de la mousse']]
        TxTQMousse = Table(TxT_QMousse)
        QMousse_val = []
        QMousse_val = [[Liste_Indices_Finaux[10]]]
        QMousseval = Table(QMousse_val)
     
        ts_Durete = TableStyle([
            ("BACKGROUND", (0, -5), (0, -5), colors.HexColor("#FFCCFF")),
        ])
        ts_Detergent = TableStyle([
            ("BACKGROUND", (0, -4), (0, -4), colors.HexColor("#FFC000")),
        ])
        ts_Hydratation = TableStyle([
            ("BACKGROUND", (0, -3), (0, -3), colors.HexColor("#D8E4BC")),
        ])
        ts_Moussant = TableStyle([
            ("BACKGROUND", (0, -2), (0, -2), colors.HexColor("#92CDDC")),
        ])
        ts_QMousse = TableStyle([
            ("BACKGROUND", (0, -1), (0, -1), colors.HexColor("#538DD5")),
        ])
        st_L1C3 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne1_Col3 = Table([[TxTDurete, Dureteval], [TxTDetergent, Detergentval], [TxTHydratation, Hydratationval], [TxTMoussant, Moussantval], [TxTQMousse, QMousseval]], [145, 55])
        Ligne1_Col3.setStyle(st_L1C3)
        Ligne1_Col3.setStyle(ts_Durete)
        Ligne1_Col3.setStyle(ts_Detergent)
        Ligne1_Col3.setStyle(ts_Hydratation)
        Ligne1_Col3.setStyle(ts_Moussant)
        Ligne1_Col3.setStyle(ts_QMousse)
        flow_Col3.append(Ligne1_Col3)
     
        # ------- Ligne 3 -------
        Titre3_2 = Paragraph("<br/>" + "Acides Gras Saturés", style=st_Titre)
        flow_Col3.append(Titre3_2)
     
        # ------- Ligne 4 -------
        # Indice Acides Gras Saturés
        #La
        TxT_La = []
        TxT_La = [['La  Laurique          C12:0']]
        TxTLa = Table(TxT_La)
        La_val = []
        La_val = [[Liste_Indices_Finaux[11]]]
        Laval = Table(La_val)
        #M
        TxT_M = []
        TxT_M = [['M  Myristique        C14:0']]
        TxTM = Table(TxT_M)
        M_val = []
        M_val = [[Liste_Indices_Finaux[12]]]
        Mval = Table(M_val)
        #P
        TxT_P = []
        TxT_P = [['P  Palmistique       C16:0']]
        TxTP = Table(TxT_P)
        P_val = []
        P_val = [[Liste_Indices_Finaux[13]]]
        Pval = Table(P_val)
        #S
        TxT_S = []
        TxT_S = [['S  Stéarique          C18:0']]
        TxTS = Table(TxT_S)
        S_val = []
        S_val = [[Liste_Indices_Finaux[14]]]
        Sval = Table(S_val)
     
        ts_AGS = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF66FF")),
        ])
        Ligne2_Col3 = Table([[TxTLa, Laval], [TxTM, Mval], [TxTP, Pval], [TxTS, Sval]], [145, 55])
        Ligne2_Col3.setStyle(st_L1C3)
        Ligne2_Col3.setStyle(ts_AGS)
        flow_Col3.append(Ligne2_Col3)
        #
     
        frame = Frame(403.34, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col3, pdf)
     
        # ===============
        # ------- Colonne 4 -------
        # ===============
        flow_Col4 = []
     
        # ------- Ligne 1 -------
        Titre4_1 = Paragraph("Acides Gras Insaturés", style=st_Titre)
        flow_Col4.append(Titre4_1)
     
        # ------- Ligne 2 -------
        # Indice Acides Gras Insaturés
        # C18
        TxT_C18 = []
        TxT_C18 = [['C18H34O3 Ricinoléique']]
        TxTC18 = Table(TxT_C18)
        C18_val = []
        C18_val = [[Liste_Indices_Finaux[15]]]
        C18val = Table(C18_val)
        # O
        TxT_O = []
        TxT_O = [['O  Oléique']]
        TxTO = Table(TxT_O)
        O_val = []
        O_val = [[Liste_Indices_Finaux[16]]]
        Oval = Table(O_val)
        # L
        TxT_L = []
        TxT_L = [['L  Linoléique']]
        TxTL = Table(TxT_L)
        L_val = []
        L_val = [[Liste_Indices_Finaux[17]]]
        Lval = Table(L_val)
        # Ln
        TxT_Ln = []
        TxT_Ln = [['Ln  Linolénique']]
        TxTLn = Table(TxT_Ln)
        Ln_val = []
        Ln_val = [[Liste_Indices_Finaux[18]]]
        Lnval = Table(Ln_val)
     
        ts_AGI = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF3399")),
        ])
        st_L2C4 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Ligne2_Col4 = Table([[TxTC18, C18val], [TxTO, Oval], [TxTL, Lval], [TxTLn, Lnval]], [145, 55])
        Ligne2_Col4.setStyle(st_L2C4)
        Ligne2_Col4.setStyle(ts_AGI)
        flow_Col4.append(Ligne2_Col4)
     
        # ------- Ligne 3 -------
        Titre4_2 = Paragraph("<br/>" + "Indices", style=st_Titre)
        flow_Col4.append(Titre4_2)
     
        # ------- Ligne 4 -------
        # # Indice I.N.S
        TxT_Indice_INS = []
        TxT_Indice_INS = [['Indice I.N.S (dureté)']]
        TxTIndiceINS = Table(TxT_Indice_INS)
        Indice_INS_val = []
        Indice_INS_val = [[Liste_Indices_Finaux[4]]]
        IndiceINSval = Table(Indice_INS_val)
     
        # # Indice IODE
        TxT_Indice_IODE = []
        TxT_Indice_IODE = [['Indice IODE (conservation)']]
        TxTIndiceIODE = Table(TxT_Indice_IODE, [133])
        IndiceIODE_val = []
        IndiceIODE_val = [[Liste_Indices_Finaux[5]]]
        IndiceIODEval = Table(IndiceIODE_val, [33])
     
        Ligne4_Col4 = Table([[TxTIndiceINS, IndiceINSval], [TxTIndiceIODE, IndiceIODEval]], [145,55])
        #
        st_L4C4 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Indices = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.yellow),
        ])
        #
        Ligne4_Col4.setStyle(st_L4C4)
        Ligne4_Col4.setStyle(Indices)
        flow_Col4.append(Ligne4_Col4)
     
        frame = Frame(620.01, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col4, pdf)
     
        # ==================
        # ------- Ligne Ajouts  --------
        # ==================
        flow_Ligne_Ajouts = []
     
        # ------- Ligne Ajouts -------
        styles = getSampleStyleSheet()
        Titre5_1 = Paragraph("Ajouts sélectionnés", style=st_Titre_Ajouts)
        Titre5_1.underlineWidth=50
        flow_Ligne_Ajouts.append(Titre5_1)
     
        # ------- Sous-ColonneX en 2 lignes -------
        pos_x = [60, 250, 440, 630, 60, 250, 440, 630]                                                # Position en x des 4 ColonneX Ligne 1 et des 4 autres ColonneX Ligne 2
        Largeur_tb = [150, 150, 150, 150, 150, 150, 150, 150]                                     # Largeur TableX
        nb = len(Listes_Ajouts_Full)                                                                            # Nb de type d'ajouts
        # print("nb", nb)
        L1 = [[290,20], [275,37], [255,55], [235,75], [220,90]]                                    # Position et Hauteur Y frame 1 à 4 de la ligne 1 (selon le nb de sélection)
        L2 = [[20], [37], [55], [75], [90]]                                                                   # Hauteur Y frame 1 à 4 de la ligne 2 (selon le nb de sélection)
        Step_Y = [[30], [50], [70], [90], [110]]                                                           # Position Y frame 1 à 4 de la Ligne 2 (selon le nb de sélection)
     
        if nb <= 4:                                                                                                    # Ligne 1  --------------  NbColonne < 4
            # print("Ligne 1  --------------  NbColonne <= 4")
            for i in range(0, nb):
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        if nb > 4:                                                                                                      # Ligne 1  -------------- NbColonne >= 4
            # print("Ligne 1  -------------- NbColonne >= 4")
            for i in range(0, 4):
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        if nb > 4:                                                                                                      # Ligne 2  -------------- NbColonne > 4
            for i in range(4 , nb):
                # print("Ligne 2  -------------- NbColonne > 4")
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    # print("L1[max_Ligne1][0] ------------------ ", L1[max_Ligne1][0], "     ",  test[max_Ligne2][0], "      ", (L1[max_Ligne1][0] - test[max_Ligne1][0]))
                    # print("L2[max_Ligne2][0] ------------------ ", L2[max_Ligne2][0])
                    frame = Frame(pos_x[i] , (L1[max_Ligne1][0] - Step_Y[max_Ligne2][0]), 150, L2[max_Ligne2][0], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        frame = Frame(20, 125, 800, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Ligne_Ajouts, pdf)
     
        # =========================
        # ------- Ligne HV prix manquant  --------
        # =========================
        st_Price = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='red'
        )
        flow_Prix = []
     
        HV_wo_Prix = Paragraph("(*) Huiles dont les prix ne sont pas indiqués : " + Liste_HV_wo_Price, style=st_Price)
        flow_Prix.append(HV_wo_Prix)
     
        frame = Frame(20, 100, 723, 20, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Prix, pdf)
        # ========================
        # ------- Ligne Rappel Sécurité  --------
        # ========================
        # # Colonne 1
        flow_PIC = []
        Retour_Chariot='''<br/><br/>'''
        P_0 = Paragraph(Retour_Chariot, style=st_Titre)
        flow_PIC.append(P_0)
     
        img_SC = Image("ICO\SC.jpg", 50, 71)
        flow_PIC.append(img_SC)
        frame = Frame(20, 20, 80, 100, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_PIC, pdf)
     
        # # Colonne 2
        st_Secure = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='red'
        )
        st_Paragraphe_Secure = ParagraphStyle(
            name='Normal',
            alignment=0,
            leftIndent=24,
            rightIndent=24,
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='black',
            leading=8                                                                                                 # interligne
        )
        st_Link = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='blue',
            leading=8                                                                                                 # interligne
        )
     
        flow_Secure = []
        # ------- Ligne 1 -------
        Titre4_1 = Paragraph("Précautions de sécurité", style=st_Secure)
        flow_Secure.append(Titre4_1)
     
        P_1 = Paragraph("Dans un lieu très bien aéré, lors de la pesée et du mélange (émulsion) de l'eau et la soude caustique, il est impératif de porter des lunettes, des gants de protection néoprène floké coton épaisseur 0.72 (EN374-3 niveau K) puis un masque adéquat." + "<br/>" + "Toujours verser lentement la soude caustique dans l’eau tiède. Utiliser uniquement un fouet et un récipient en inox de préférence. ", style=st_Paragraphe_Secure)
        flow_Secure.append(P_1)
     
        text1='''<br/><a href=https://www.vdp.com/FR/Nieuws/date/desc/1/2269/0/en-374-2016-profond-changement-de-la-norme-relative-aux-gants-resistant-aux-produits-chimiques.html><u>EN 374, la norme relative aux gants résistant aux produits chimiques</u></a>'''
        P_2 = Paragraph(text1, style=st_Link)
        flow_Secure.append(P_2)
     
        text2='''<a href=http://www.inrs.fr/publications/bdd/fichetox/fiche.html?refINRS=FICHETOX_20><u>Hydroxyde de sodium et solutions aqueuses</u></a>'''
        P_3 = Paragraph(text2, style=st_Link)
        flow_Secure.append(P_3)
     
        text3='''<a href=https://www.protecthoms.com/normes-masque-hygiene><u>Protection contre les aérosols solides ou liquides toxiques</u></a>'''
        P_4 = Paragraph(text3, style=st_Link)
        flow_Secure.append(P_4)
     
        frame = Frame(100, 20, 723, 80, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
        frame.addFromList(flow_Secure, pdf)
     
        pdf.save()
     
     
        # ===================
        #        --- Création TxT ---
        # ===================
     
        # r     ouverture en lecture (READ).
        # w     ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé. Si le fichier n'existe pas, il sera créé
        # a     ouverture en mode ajout à la fin du fichier (APPEND). Si le fichier n'existe pas, il sera créé
        # b     ouverture en mode binaire.
        # t     ouverture en mode texte.
        # x     crée un nouveau fichier et l'ouvre pour écriture
     
        # ------- Nom Dossier & Fichier PDF Cible -------
        Nom_File_txt = Nom_Rec.get() + ".txt"
        print("Nom_File_txt", Nom_File_txt)
        # 1 -- Création du ficher cilbe
        # os.path.join prend un répertoire et un nom de fichier et les concatène pour former un chemin d'accès complet.
        with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
            pass
        # Fermeture du fichier
        file_object.close()
     
        # 2 -- Ecriture Titre Recette
        # L'instruction with garantie la fermeture du fichier en fin de bloc
        # w -- Ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé.
        with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
            # Ajout 1er. ligne
            file_object.write(Nom_Rec.get() + '\n' + '\n')
        file_object.close()
     
        # 3 -- Ecriture Liste HV Qt Prix INCI SAP
                # - Création d'un tableau type Tuples -
        # exemple : [('Coco Vierge CHAOKOH', 120.0, 1.704, 'Sodium Cocoate'), ('Olive Filipo', 100.0, 0.62, 'Sodium Olivate'), ('Argan-yari', 16.8, 0.551, 'Sodium Arganate'), ('Babassu', 25.63, 0, 'Sodium Babassuate')]
        a = []
        b =[]
        c = []
        d = []
        combs = []
        for u in range(0, len(Liste_Full)):
            a.append(Liste_Full[u][0])
            b.append(str(Liste_Full[u][2]))
            c.append(str(Liste_Full[u][24]))
            d.append(Liste_Full[u][25])
        # print(a, '\n', b, '\n', c)
        for i in range(0, len(a)):
            x = a[i]
            y = b[i]
            z = c[i]
            w = d[i]
            combs.append((x,y,z,w))
        # print("combs", combs, type(combs))
        # print("combs", type(combs))
     
                # - Titre des colonnes -
        columnNames = ("Nom Huile", "Quantité gr.", "Prix", "Nom INCI SAP")
     
                # - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
        columnSizes = [0, 0, 0, 0]
        for column in range(4):
            maxSize = len(columnNames[column])
            for line in combs:
                maxSize = max(len(line[column]), maxSize)
            columnSizes[column] = maxSize
     
                # - Formats des lignes utilisés pour écrire dans le fichier -
                # calcule : +------------+------------+-----------+---------------+
        separatorRow = "+%s+%s+%s+%s+" % ("-" * (columnSizes[0] + 2),
                                          "-" * (columnSizes[1] + 2),
                                          "-" * (columnSizes[2] + 2),
                                          "-" * (columnSizes[3] + 2))
                # calcule : | %-10s | %-10s | %-9s | %13s |
        lineFormat = "| %%-%ds | %%-%ds | %%-%ds | %%%ds |" % (columnSizes[0], columnSizes[1], columnSizes[2], columnSizes[3])
     
                # - Ecriture dans le ficher avec les données formatées -
        try:
            # L'instruction with garantie la fermeture du fichier en fin de bloc
            with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
                print(separatorRow, file=file_object)
                print(lineFormat % columnNames, file=file_object)
                print(separatorRow, file=file_object)
                for mot in combs:
                    # mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
                    print(lineFormat % mot, file=file_object)
                print(separatorRow, file=file_object)
            # print("File generated")
        except IOError as exception:
            print("Cannot write data to file " + str(exception), file=sys.stderr)
     
        file_object.close()
     
        # 4 -- Ecriture Liste Ajouts et une deuxième colonne
               # - Conversion List in List  en une simple List -
        from collections import Iterable
        def flatten(Listes_Ajouts_Full):
            for item in Listes_Ajouts_Full:
                if isinstance(item, Iterable) and not isinstance(item, str):
                    for x in flatten(item):
                        yield x
                else:
                    yield item
        result = list(flatten(Listes_Ajouts_Full))
        # print("list", list, result)                                                                                    # exemple : ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
     
                # - Ajout d'un deuxième paramètre  -
        DP = []
        for i in range(0, len(result)):
            DP.append(result[i])
            DP.append("...")
        # print("DP       ", DP)                                                                                      # exemple : ['Acide Stéarique', '...', 'Acide Palmitique', '...', 'Acide Oléique', '...', 'Acide Myristique', '...', 'Acide Laurique', '...', 'Extrait CO2 de Romarin BIO', '...', 'Vitanime E naturel', '...', 'ARG - Rouge', '...', 'Aloe vera', '...', 'Lait', '...', 'Lait de coco', '...', 'Miel', '...', 'Violette', '...', 'Arbre à thè [Tea Tree]', '...', 'Camomille Romaine', '...', 'Geranium Rosat', '...', 'Hydroxyéthyl Cellulose (HEC)', '...', 'Cacao', '...', 'Café', '...', 'Cannelle', '...', 'Carthame', '...']
     
            # - Construction  simple List par paire -
        a = []
        b = []
        combs = []
        for u in range(0, len(DP), 2):                                                                          # List a pour les nom des Ajouts --> ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
            a.append(DP[u])
        for u in range(1, len(DP), 2):                                                                          # List b pour le deuxième paramètre -->  ['...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...']
            b.append(DP[u])
        # print(a, '\n', b)
        for i in range(0, len(a)):
            x = a[i]
            y = b[i]
            combs.append((x,y))
        # print("combs", combs, type(combs))                                                                # [('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...')] <class 'list'>
        # print("combs", type(combs))                                                                           # <class 'list'>
                # - Conversion simple List en Tuple -
        tup = tuple(combs)
        # print("tuple(combs)    ", tup)                                                                           #  (('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...'))
     
                # - Titre des colonnes -
        columnNames = ("Nom Ajouts", "Quantité gr.")
     
                # - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
        columnSizes = [0,0]
        for column in range(2):
            maxSize = len(columnNames[column])
            for line in tup:
                maxSize = max(len(line[column]), maxSize)
            columnSizes[column] = maxSize
     
                # - Formats des lignes utilisés pour écrire dans le fichier -
                # calcule : +------------+------------+-----------+---------------+
        separatorRow = "+%s+%s+" % ("-" * (columnSizes[0] +2),
                                                        "-" * (columnSizes[1] + 2))
                # calcule : | %-10s | %-10s | %-9s | %13s |
        lineFormat = "| %%-%ds | %%-%ds |" % \
                     (columnSizes[0], columnSizes[1])
     
                # - Ecriture dans le ficher avec les données formatées -
        try:
            # L'instruction with garantie la fermeture du fichier en fin de bloc
            with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
                print(separatorRow, file=file_object)
                print(lineFormat % columnNames, file=file_object)
                print(separatorRow, file=file_object)
                for mot in tup:
                    # mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
                    print(lineFormat % mot, file=file_object)
                print(separatorRow, file=file_object)
            # print("File generated")
        except IOError as exception:
            print("Cannot write data to file " + str(exception), file=sys.stderr)
     
     
     
        # a -- Ouverture en mode ajout à la fin du fichier (APPEND)
        # with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a') as file_object:
        #     # Ajout texte en fin de fichier
        #     for u in range(0, len(Liste_Full)):
        #         file_object.write(str(Liste_Full[u][0]) + "\t" + "\t" + str(Liste_Full[u][2]) + '\n')
        # file_object.close()
     
     
     
        # Vidange des liste suivantes - cela permet générer à nouveau un PDF (avec ou sans les mêmes ajouts)
        Elements[:] = []
        Element_Ligne1[:] = []
        Element_Ligne2[:] = []
        Listes_Ajouts_Full[:] = []
        Liste_Ajouts1[:] = []
        Liste_Ajouts2[:] = []
        Liste_Ajouts3[:] = []
        Liste_Ajouts4[:] = []
        Liste_Ajouts5[:] = []
        Liste_Ajouts6[:] = []
        Liste_Ajouts7[:] = []
        Liste_Ajouts8[:] = []
    le plus important ce trouve ici : --> rl_config.TTFSearchPath.append('C:/!TEST!/_TEST_/Fonts')
    ce qui permet d'embarquer les TTF dans le projet
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
      import reportlab
        from reportlab.pdfgen import canvas
        from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.lib.units import mm
     
        # Format de la feuille
        from reportlab.lib.pagesizes import landscape
        from reportlab.lib.pagesizes import A4
     
        # Police Verdana
        from reportlab.pdfbase.pdfmetrics import registerFont
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont
        from reportlab import rl_config
     
        rl_config.TTFSearchPath.append('C:/!TEST!/_TEST_/Fonts')
     
        registerFont(TTFont('Verdana', 'VERDANA.TTF'))
        registerFont(TTFont('Verdana-Bold', 'VERDANAB.TTF'))
        registerFont(TTFont('Verdana-Italic', 'VERDANAI.TTF'))
        registerFont(TTFont('Verdana-BoldItalic', 'VERDANAZ.TTF'))
     
        registerFont(TTFont('THSarabun', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-Bold', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-italic', 'THSarabun.ttf'))
        registerFont(TTFont('THSarabun-BoldItalic', 'THSarabun.ttf'))
     
        registerFont(TTFont('arabtype', 'arabtype.TTF'))
    sous pycharm ça fonctionne bien (j'ai bien sûr supprimer les polices dans C:\Windows\Fonts) avant les tests

    effectivement j'obtient toujours une erreur en le compilant.

    voici le fichier de configuration de auto-py-to-exe (json)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
     
    {
     "version": "auto-py-to-exe-configuration_v1",
     "pyinstallerOptions": [
      {
       "optionDest": "noconfirm",
       "value": true
      },
      {
       "optionDest": "filenames",
       "value": "C:/!TEST!/_TEST_/Compile_5/Main.py"
      },
      {
       "optionDest": "onefile",
       "value": true
      },
      {
       "optionDest": "console",
       "value": false
      },
      {
       "optionDest": "icon_file",
       "value": "C:/!TEST!/_TEST_/Compile_5/ICO/Soap_0.ico"
      },
      {
       "optionDest": "ascii",
       "value": false
      },
      {
       "optionDest": "clean_build",
       "value": false
      },
      {
       "optionDest": "strip",
       "value": false
      },
      {
       "optionDest": "noupx",
       "value": false
      },
      {
       "optionDest": "uac_admin",
       "value": false
      },
      {
       "optionDest": "uac_uiaccess",
       "value": false
      },
      {
       "optionDest": "win_private_assemblies",
       "value": false
      },
      {
       "optionDest": "win_no_prefer_redirects",
       "value": false
      },
      {
       "optionDest": "bootloader_ignore_signals",
       "value": false
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB;.DB/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_5/DOC;.DOC/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_5/ICO;.ICO/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_5/Recettes;.Recettes/"
      },
      {
       "optionDest": "hiddenimports",
       "value": "pkg_resources.py2_warn"
      },
      {
       "optionDest": "hookspath",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB"
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/AE.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/AG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/ALC.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/AO.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/ARG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/Divers.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/FRAG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/HE.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/HV.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/Recettes.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/DB/TT.db;."
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts;.Fonts/"
      },
      {
       "optionDest": "hookspath",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts"
      },
      {
       "optionDest": "pathex",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts"
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/arabtype.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/THSarabun Bold Italic.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/THSarabun Bold.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/THSarabun Italic.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/THSarabun.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/verdana.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/verdanab.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/verdanai.ttf;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_5/Fonts/verdanaz.ttf;."
      }
     ],
     "nonPyinstallerOptions": {
      "increaseRecursionLimit": true,
      "manualArguments": ""
     }
    }

  9. #9
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 462
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 462
    Points : 9 249
    Points
    9 249
    Billets dans le blog
    6
    Par défaut
    Peut-être ceux qui connaissent reportlab peuvent proposer une solution géniale, mais à défaut, vous pouvez toujours appliquer ma solution comme suit:

    - dans le répertoire du projet, créer un répertoire "fonts".

    - placer dedans les fichiers des polices à intégrer. J'ai placé dedans les fichiers de la police "Vera", après m'être assuré qu'elles ne se trouvaient pas dans Windows (pour valider l'essai).

    - j'ai modifié mon code pour n'avoir que la police Vera à intégrer:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    import sys
     
    import os
    import reportlab
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfgen.canvas import Canvas
     
    if getattr(sys, 'frozen', False):
        folder = os.path.join(sys._MEIPASS, "fonts") # programma traité par pyinstaller
    else:
        folder = os.path.join(os.path.dirname(__file__), 'fonts') # programme non traité
     
    ttfFile = os.path.join(folder, 'Vera.ttf')
    pdfmetrics.registerFont(TTFont("Vera", ttfFile))
     
    canvas = Canvas('TestFonts.pdf')
    canvas.setFont('Vera', 32)
    canvas.drawString(10, 250, 'This should be drawn in')
    canvas.drawString(10, 200, 'the font Vera')
     
    canvas.showPage()
    canvas.save()
    - modifier la ligne du script bat pour copier le répertoire fonts pendant le traitement par pyinstaller. La 1ère adresse est le répertoire du programme (mettre le bon chemin):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    --add-data "E:\Pythondev\Pydev\projetpython\reportlab\fonts;fonts" ^
    Et ça marche dans tous les cas: .pyw, .exe avec option onedir et .exe avec option onefile.
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

  10. #10
    Invité
    Invité(e)
    Par défaut
    j'ai testé votre solution et est compris sont fonctionnement.
    je l'ai appliqué à mon code fonctionnant sans soucis dans pycharm
    j'ai toujours une erreur lors du lancement exe.
    le répertoire est Fonts est bien crée et contient toutes les polices d'origine + les miennes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
     
    # coding:utf-8
    #version 3.x python
    # ---------------------------------------------------------
    #                                 Modules
    # ---------------------------------------------------------
    import sys
    import os.path
    from os import path
     
    from tkinter import *
    from tkinter.ttk import *
     
     
    def TABLES(Liste_Full, Liste_Somme, Liste_Indices_Finaux, Nom_Rec, Liste_Ajouts1, Liste_Ajouts2, Liste_Ajouts3, Liste_Ajouts4, Liste_Ajouts5, Liste_Ajouts6, Liste_Ajouts7, Liste_Ajouts8, Qt_TT_Recette, prix):
        print("\n" + "<--- Liste des information nécessaire pour le PDF_Build --->")
        print("<--->	Nom_Recette				", Nom_Rec.get())
        print("<--->	Liste_Full					", Liste_Full)
        print("<--->	Liste_Somme				", Liste_Somme)
        print("<--->	Liste_Indices_Finaux	", Liste_Indices_Finaux)
        print("<--->	Liste_Ajouts1				", Liste_Ajouts1)
        print("<--->	Liste_Ajouts2				", Liste_Ajouts2)
        print("<--->	Liste_Ajouts3				", Liste_Ajouts3)
        print("<--->	Liste_Ajouts4				", Liste_Ajouts4)
        print("<--->	Liste_Ajouts5				", Liste_Ajouts5)
        print("<--->	Liste_Ajouts6				", Liste_Ajouts6)
        print("<--->	Liste_Ajouts7				", Liste_Ajouts7)
        print("<--->	Liste_Ajouts8				", Liste_Ajouts8)
        print("<--->	Poids Recette				", Qt_TT_Recette)
        print("<--->	Prix Recette				", prix)
        print("\n")
     
        # Référence les HV sans Prix
        HV_NoPrix = []
        HV_NoPrix[:] = []
        for u in range(0, len(Liste_Full)):
            # print("HV", Liste_Full[u][0], "        Prix", Liste_Full[u][24])
            if Liste_Full[u][24] == 0:
                HV_NoPrix.append(Liste_Full[u][0])
        # print("HV_NoPrix - Huile sans prix", HV_NoPrix)                                                # ex : ['Babassu', 'Arachide', 'Amande douce']
        Liste_HV_wo_Price = StringVar()
        Liste_HV_wo_Price = ""
        for u in range(0, len(HV_NoPrix)):
            Liste_HV_wo_Price = Liste_HV_wo_Price + "               " + HV_NoPrix[u]
        # print("Liste_HV_wo_Price", Liste_HV_wo_Price)
        HV_NoPrix[:] = []
     
        # Encapsulation des Liste_AjoutsX dans Listes_Ajouts_Full
        # Enregistre le nombre d'éléments de chaque Liste_AjoutsX
        Compteur = 0                                                                                               # Compteur le Nb de Liste_AjoutsX non vide
        Elements = []                                                                                                # Contient le Nb Items de chaque Liste_AjoutsX
        Element_Ligne1 =[]                                                                                       # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 1
        Element_Ligne2 = []                                                                                      # Contient le Nb Items sur les 4 premières Liste_AjoutsX constituant la Ligne 2
        Listes_Ajouts_Full =[]
        if len(Liste_Ajouts1) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts1)
            # print("Listes_Ajouts_Full - Liste_Ajouts1", Listes_Ajouts_Full)
            if len(Liste_Ajouts1) > 0:
                Elements.append(len(Liste_Ajouts1))
                Compteur = Compteur + 1
        if len(Liste_Ajouts2) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts2)
            # print("Listes_Ajouts_Full - Liste_Ajouts2", Listes_Ajouts_Full)
            if len(Liste_Ajouts2) > 0:
                Elements.append(len(Liste_Ajouts2))
                Compteur = Compteur + 1
        if len(Liste_Ajouts3) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts3)
            # print("Listes_Ajouts_Full - Liste_Ajouts3", Listes_Ajouts_Full)
            if len(Liste_Ajouts3) > 0:
                Elements.append(len(Liste_Ajouts3))
                Compteur = Compteur + 1
        if len(Liste_Ajouts4) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts4)
            # print("Listes_Ajouts_Full - Liste_Ajouts4", Listes_Ajouts_Full)
            if len(Liste_Ajouts4) > 0:
                Elements.append(len(Liste_Ajouts4))
                Compteur = Compteur + 1
        if len(Liste_Ajouts5) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts5)
            # print("Listes_Ajouts_Full - Liste_Ajouts5", Listes_Ajouts_Full)
            if len(Liste_Ajouts5) > 0:
                Elements.append(len(Liste_Ajouts5))
                Compteur = Compteur + 1
        if len(Liste_Ajouts6) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts6)
            # print("Listes_Ajouts_Full - Liste_Ajouts6", Listes_Ajouts_Full)
            if len(Liste_Ajouts6) > 0:
                Elements.append(len(Liste_Ajouts6))
                Compteur = Compteur + 1
        if len(Liste_Ajouts7) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts7)
            # print("Listes_Ajouts_Full - Liste_Ajouts7", Listes_Ajouts_Full)
            if len(Liste_Ajouts7) > 0:
                Elements.append(len(Liste_Ajouts7))
                Compteur = Compteur + 1
        if len(Liste_Ajouts8) != 0:
            Listes_Ajouts_Full.append(Liste_Ajouts8)
            # print("Listes_Ajouts_Full - Liste_Ajouts8", Listes_Ajouts_Full)
            if len(Liste_Ajouts8) > 0:
                Elements.append(len(Liste_Ajouts8))
                Compteur = Compteur + 1
     
        # print("len(Listes_Ajouts_Full) -- Listes_Ajouts_Full", len(Listes_Ajouts_Full), "       ", Listes_Ajouts_Full)
        # for u in range(0, len(Listes_Ajouts_Full)):
        #     for z in range(0, len(Listes_Ajouts_Full[u])):
                # print("Listes_Ajouts_Full[", u, "][", z, "]", Listes_Ajouts_Full[u][z])
     
        # Regroupe le Nb Item par tranche de 4 colonnes pour chaque ligne d'affichage
        # print("Elements", Elements)
        # print("Compteur", Compteur)
        if len(Elements) <= 4:
            for i in range(0, Compteur):
                Element_Ligne1.append(Elements[i])
            # print("Element_Ligne1 -- <= 4", Element_Ligne1)
            max_Ligne1 = IntVar()
            if Element_Ligne1 == []:
                max_Ligne1 = 0
            if Element_Ligne1 != []:
                max_Ligne1 = max(Element_Ligne1) - 1
                # print("max_Ligne1", max_Ligne1)
     
        if len(Elements) >= 4:
            for i in range(0, 4):
                Element_Ligne1.append(Elements[i])
            # print("Element_Ligne1 -- >= 4", Element_Ligne1)
            max_Ligne1 = IntVar()
            max_Ligne1 = max(Element_Ligne1) - 1
            # print("max_Ligne1", max_Ligne1)
            Solde_Compteur = Compteur - (Compteur - 4)
            # print("Solde_Compteur", Solde_Compteur)
     
            for j in range(Solde_Compteur, Compteur):
                Element_Ligne2.append(Elements[j])
            # print("Element_Ligne2 -- >= 4", Element_Ligne2)
            max_Ligne2 = IntVar()
            if Element_Ligne2 == []:
                max_Ligne2 = 0
            if Element_Ligne2 != []:
                max_Ligne2 = max(Element_Ligne2) - 1
                # print("max_Ligne2", max_Ligne2)
     
        # ===================
        #        --- Création PDF ---
        # ===================
        import reportlab
        #
        from reportlab.lib import colors
        from reportlab.pdfgen import canvas
        from reportlab.platypus import Paragraph, Table, TableStyle, Frame, Image, ParagraphAndImage
        from reportlab.lib.styles import ParagraphStyle
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.lib.units import mm
     
        # Format de la feuille
        from reportlab.lib.pagesizes import landscape
        from reportlab.lib.pagesizes import A4
     
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont
     
        # modif du calcul du chemin du répertoire "fonts"
        if getattr(sys, 'frozen', False):
            folder = os.path.join(sys._MEIPASS, "fonts")  # programma traité par pyinstaller
        else:
            folder = os.path.join(os.path.dirname(reportlab.__file__), 'fonts')  # programme non traité
     
        # Chargement des Polices de caractères
        TTF_File1 = os.path.join(folder, 'verdana.ttf')
        pdfmetrics.registerFont(TTFont("Verdana", TTF_File1))
        TTF_File2 = os.path.join(folder, 'verdanab.ttf')
        pdfmetrics.registerFont(TTFont("Verdana-Bold", TTF_File2))
        TTF_File3 = os.path.join(folder, 'verdanai.ttf')
        pdfmetrics.registerFont(TTFont("Verdana-Italic", TTF_File3))
        TTF_File4 = os.path.join(folder, 'verdanaz.ttf')
        pdfmetrics.registerFont(TTFont("Verdana-BoldItalic", TTF_File4))
        #
        TTF_File5 = os.path.join(folder, 'arabtype.ttf')
        pdfmetrics.registerFont(TTFont("arabtype", TTF_File5))
        #
        TTF_File6 = os.path.join(folder, 'THSarabun.ttf')
        pdfmetrics.registerFont(TTFont("THSarabun", TTF_File6))
        TTF_File7 = os.path.join(folder, 'THSarabun Bold.ttf')
        pdfmetrics.registerFont(TTFont("THSarabun-Bold", TTF_File7))
        TTF_File8 = os.path.join(folder, 'THSarabun Italic.ttf')
        pdfmetrics.registerFont(TTFont("THSarabun-italic", TTF_File8))
        TTF_File9 = os.path.join(folder, 'THSarabun Bold Italic.ttf')
        pdfmetrics.registerFont(TTFont("THSarabun-BoldItalic", TTF_File9))
     
        # ===================
        # ------- Styles TitreX_X -------
        # ===================
        # alignmemt -- Valeur :  0 Gauche -- 1 Centrer -- 2 Droite --
        st_Titre = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='blue'
        )
        st_Titre_Ajouts = ParagraphStyle(
            name='Normal',
            alignment=0,
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='blue'
        )
     
        # ===============================
        # ------- Nom Fichier Cible PDF & Titre PAGE -------
        # ===============================
        # Identifie PID du processus ...
        os.system("tasklist | findstr /I Acrobat.exe")
        os.system("tasklist | findstr /I AcroRd32.exe")
        # Tue le processus ...
        os.system("taskkill /f /im Acrobat.exe")                                                           # Acrobat Reader
        os.system("taskkill /f /im AcroRd32.exe")                                                         # Acrobat Reader
     
        # ------- Dossier Cible & Nom fichier PDF -------
        Dossier_Cible = 'Recettes'
        Nom_File = Nom_Rec.get() + ".pdf"
     
        # Vérifie la présence du dossier cible
        try:
            os.makedirs(Dossier_Cible)
            print("Directory    ", Dossier_Cible,  " Created ")
        except FileExistsError:
            print("Directory    ", Dossier_Cible,  " already exists")
     
        # Ecriture du fichier cible
        pdf = canvas.Canvas(Dossier_Cible + "/" + Nom_File, 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",
        )
        # Identification de la langue utilisée pour le titre de la recette puis orientation vers la bon style
        # from langdetect import detect                                                                         # Détecte la langue d'un texte, d'une variable string
        # Titre_Recette = ""
        # lang_Nom_Rec = detect(Nom_Rec.get())                                                          # detect la langue utilisée pour le titre
        # print("lang_Nom_Rec", lang_Nom_Rec, type(lang_Nom_Rec))
        # if lang_Nom_Rec == "it":
        Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_EU)
        # if lang_Nom_Rec == "th":
        #     Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_TH)
        # if lang_Nom_Rec == "ar":
        #     Titre_Recette = Paragraph(Nom_Rec.get(), style=stl_Recette_AR)
        # print("Titre de la recette", Titre_Recette)
        '''
        Titre de la recette Paragraph(
        'caseSensitive': 1
        'encoding': 'utf8'
        'text': 'Nouveau Nom Recette Test - Coincoin - 20.06.2020'
        'frags': [ParaFrag(__tag__='para', bold=1, fontName='Verdana-Bold', fontSize=24, greek=0, italic=1, link=[], rise=0, text='Nouveau Nom Recette Test - Coincoin - 20.06.2020', textColor='#7E2300', us_lines=[])]
        'style': <ParagraphStyle 'Normal'>
        'bulletText': None
        'debug': 0
        ) #Paragraph
        '''
        flow_Ligne1.append(Titre_Recette)
     
        frame = Frame(20, 540, 800, 30, showBoundary=0)
        frame.addFromList(flow_Ligne1, pdf)
     
        # ===============
        # ------- Colonne 1 -------
        # ===============
        flow_Col1 = []
     
        # ------- Ligne 1 -------
        Titre1_1 = Paragraph("Huiles - gr.", style=st_Titre)
        flow_Col1.append(Titre1_1)
     
        # ------- Ligne 2 -------
        # # Nom HV
        HV_Nom = []
        HV_Nom = [[u[0]] for u in Liste_Full]
        tb_HVNom = Table(HV_Nom, len(HV_Nom) * [45 * mm], len(HV_Nom) * [5 * mm])
        # # Qt HV
        HV_Qt = []
        HV_Qt = [[u[2]] for u in Liste_Full]
        tb_HVQt = Table(HV_Qt, len(HV_Qt) * [15 * mm], len(HV_Qt) * [5 * mm])
     
        Ligne2_Col1 = Table([[tb_HVNom, tb_HVQt]], [140,50])
     
        st_L2C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Ligne2_Col1.setStyle(st_L2C1)
        flow_Col1.append(Ligne2_Col1)
     
        # ------- Ligne 3 -------
        Titre1_2 = Paragraph("<br/>" + "Hydroxyde de sodium & H2O - gr.", style=st_Titre)
        flow_Col1.append(Titre1_2)
     
        # ------- Ligne 4 -------
        # # SC TT Qt
        TxT_SC_TT_Qt = []
        TxT_SC_TT_Qt = [['Soude Caustique - NaOH']]
        TxTSC_TT_Qt = Table(TxT_SC_TT_Qt)
        SC_TT_Qt = []
        SC_TT_Qt = [[Liste_Indices_Finaux[2]]]
        SCTT_Qt = Table(SC_TT_Qt)
     
        # # Eau TT Qt
        TxT_H2O_TT_Qt = []
        TxT_H2O_TT_Qt = [['Eau distillée']]
        TxTH2O_TT_Qt = Table(TxT_H2O_TT_Qt)
        H2O_TT_Qt = []
        H2O_TT_Qt = [[Liste_Indices_Finaux[3]]]
        H2OTT_Qt = Table(H2O_TT_Qt)
     
        Ligne4_Col1 = Table([[TxTSC_TT_Qt, SCTT_Qt], [TxTH2O_TT_Qt, H2OTT_Qt]], [140,50])
        #
        st_L4C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne4_Col1.setStyle(st_L4C1)
        flow_Col1.append(Ligne4_Col1)
     
        # ------- Ligne 5 -------
        Titre1_3 = Paragraph("<br/>" + "Réduction & Concentration", style=st_Titre)
        flow_Col1.append(Titre1_3)
     
        # ------- Ligne 6 -------
        # # Réduction de soude caustique
        TxT_Reduc_Soude = []
        TxT_Reduc_Soude = [['Réduction soude caustique']]
        TxTReducSoude = Table(TxT_Reduc_Soude)
        Reduc_Soude_Qt = []
        Reduc_Soude_Qt = [[Liste_Indices_Finaux[0]]]
        ReducSoudeQt = Table(Reduc_Soude_Qt)
     
        # # Concentration Lessive
        TxT_Concentration_Lessive = []
        TxT_Concentration_Lessive = [['Concentration Lessive']]
        TxTConcentrationLessive = Table(TxT_Concentration_Lessive)
        Concentration_Lessive_Qt = []
        Concentration_Lessive_Qt = [[Liste_Indices_Finaux[1]]]
        ConcentrationLessiveQt = Table(Concentration_Lessive_Qt)
     
        Ligne6_Col1 = Table([[TxTReducSoude, ReducSoudeQt], [TxTConcentrationLessive, ConcentrationLessiveQt]], [140,50])
        #
        st_L6C1 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne6_Col1.setStyle(st_L6C1)
        flow_Col1.append(Ligne6_Col1)
     
        frame = Frame(20, 330, 190, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col1, pdf)
     
        # ===============
        # ------- Colonne 2 -------
        # ===============
        flow_Col2 = []
     
        # ------- Ligne 1 -------
        Titre2_1 = Paragraph("Poids - gr.", style=st_Titre)
        flow_Col2.append(Titre2_1)
     
        # ------- Ligne 2 -------
        # # HV TT Qt
        TxT_HV_TT_Qt = []
        TxT_HV_TT_Qt = [['Huiles']]
        TxTHVTTQt = Table(TxT_HV_TT_Qt)
        HV_TT_Qt = []
        HV_TT_Qt = [[Liste_Somme[0]]]
        HVTTQt = Table(HV_TT_Qt)
     
        # # Qt TT Recette
        TxT_Rec_TT_Qt = []
        TxT_Rec_TT_Qt = [['Recette']]
        TxTTT_Qt = Table(TxT_Rec_TT_Qt, [133])
        Rec_TT_Qt = []
        Rec_TT_Qt = [[Qt_TT_Recette]]
        RecTT_Qt = Table(Rec_TT_Qt, [33])
     
        Ligne1_Col2 = Table([[TxTHVTTQt, HVTTQt], [TxTTT_Qt, RecTT_Qt]], [105,55])
        #
        st_L1C2 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne1_Col2.setStyle(st_L1C2)
        flow_Col2.append(Ligne1_Col2)
     
        # ------- Ligne 3 -------
        st_Red = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='red'
        )
     
        flow_Prix = []
        Titre2_2 = Paragraph("<br/>" +"Coût de revient", style=st_Titre)
        Titre2_2a = Paragraph("(*)", style=st_Red)
        Titre2_final = Table([[Titre2_2, Titre2_2a]], [90, 80])
        flow_Col2.append(Titre2_final)
     
        # ------- Ligne 4 -------
        # # HV Prix
        TxT_HV_Prix = []
        TxT_HV_Prix = [['Recette']]
        TxTHVPrix = Table(TxT_HV_Prix)
        HV_Prix = []
        HV_Prix = [[prix]]
        HVPrix = Table(HV_Prix)
     
        Ligne2_Col2 = Table([[TxTHVPrix, HVPrix]], [105,55])
        #
        st_L2C2 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne2_Col2.setStyle(st_L2C2)
        flow_Col2.append(Ligne2_Col2)
     
        # ------- Ligne 5 -------
        DateStart = Paragraph("<br/>" + "Date de création", style=st_Titre)
        flow_Col2.append(DateStart)
        Cure = Paragraph("<br/>" + "Temps de séquestration", style=st_Titre)
        flow_Col2.append(Cure)
        Ph = Paragraph("<br/>" + "Mesure Ph", style=st_Titre)
        flow_Col2.append(Ph)
     
        frame = Frame(226.67, 330, 160, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col2, pdf)
     
        # ===============
        # ------- Colonne 3 -------
        # ===============
        flow_Col3 = []
     
        # ------- Ligne 1 -------
        Titre3_1 = Paragraph("Propriétés du savon", style=st_Titre)
        flow_Col3.append(Titre3_1)
     
        # ------- Ligne 2 -------
        # Indice Dureté
        TxT_Durete = []
        TxT_Durete = [['Dureté']]
        TxTDurete = Table(TxT_Durete)
        Durete_val = []
        Durete_val = [[Liste_Indices_Finaux[6]]]
        Dureteval = Table(Durete_val)
        # Indice Détergent
        TxT_Detergent = []
        TxT_Detergent = [['Détergent']]
        TxTDetergent = Table(TxT_Detergent)
        Detergent_val = []
        Detergent_val = [[Liste_Indices_Finaux[7]]]
        Detergentval = Table(Detergent_val)
        # Indice Hydratation
        TxT_Hydratation = []
        TxT_Hydratation = [['Hydratation']]
        TxTHydratation = Table(TxT_Hydratation)
        Hydratation_val = []
        Hydratation_val = [[Liste_Indices_Finaux[8]]]
        Hydratationval = Table(Hydratation_val)
        # Indice Moussant
        TxT_Moussant = []
        TxT_Moussant = [['Moussant']]
        TxTMoussant = Table(TxT_Moussant)
        Moussant_val = []
        Moussant_val = [[Liste_Indices_Finaux[9]]]
        Moussantval = Table(Moussant_val)
        # Indice QMousse
        TxT_QMousse = []
        TxT_QMousse = [['Qualité de la mousse']]
        TxTQMousse = Table(TxT_QMousse)
        QMousse_val = []
        QMousse_val = [[Liste_Indices_Finaux[10]]]
        QMousseval = Table(QMousse_val)
     
        ts_Durete = TableStyle([
            ("BACKGROUND", (0, -5), (0, -5), colors.HexColor("#FFCCFF")),
        ])
        ts_Detergent = TableStyle([
            ("BACKGROUND", (0, -4), (0, -4), colors.HexColor("#FFC000")),
        ])
        ts_Hydratation = TableStyle([
            ("BACKGROUND", (0, -3), (0, -3), colors.HexColor("#D8E4BC")),
        ])
        ts_Moussant = TableStyle([
            ("BACKGROUND", (0, -2), (0, -2), colors.HexColor("#92CDDC")),
        ])
        ts_QMousse = TableStyle([
            ("BACKGROUND", (0, -1), (0, -1), colors.HexColor("#538DD5")),
        ])
        st_L1C3 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        #
        Ligne1_Col3 = Table([[TxTDurete, Dureteval], [TxTDetergent, Detergentval], [TxTHydratation, Hydratationval], [TxTMoussant, Moussantval], [TxTQMousse, QMousseval]], [145, 55])
        Ligne1_Col3.setStyle(st_L1C3)
        Ligne1_Col3.setStyle(ts_Durete)
        Ligne1_Col3.setStyle(ts_Detergent)
        Ligne1_Col3.setStyle(ts_Hydratation)
        Ligne1_Col3.setStyle(ts_Moussant)
        Ligne1_Col3.setStyle(ts_QMousse)
        flow_Col3.append(Ligne1_Col3)
     
        # ------- Ligne 3 -------
        Titre3_2 = Paragraph("<br/>" + "Acides Gras Saturés", style=st_Titre)
        flow_Col3.append(Titre3_2)
     
        # ------- Ligne 4 -------
        # Indice Acides Gras Saturés
        #La
        TxT_La = []
        TxT_La = [['La  Laurique          C12:0']]
        TxTLa = Table(TxT_La)
        La_val = []
        La_val = [[Liste_Indices_Finaux[11]]]
        Laval = Table(La_val)
        #M
        TxT_M = []
        TxT_M = [['M  Myristique        C14:0']]
        TxTM = Table(TxT_M)
        M_val = []
        M_val = [[Liste_Indices_Finaux[12]]]
        Mval = Table(M_val)
        #P
        TxT_P = []
        TxT_P = [['P  Palmistique       C16:0']]
        TxTP = Table(TxT_P)
        P_val = []
        P_val = [[Liste_Indices_Finaux[13]]]
        Pval = Table(P_val)
        #S
        TxT_S = []
        TxT_S = [['S  Stéarique          C18:0']]
        TxTS = Table(TxT_S)
        S_val = []
        S_val = [[Liste_Indices_Finaux[14]]]
        Sval = Table(S_val)
     
        ts_AGS = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF66FF")),
        ])
        Ligne2_Col3 = Table([[TxTLa, Laval], [TxTM, Mval], [TxTP, Pval], [TxTS, Sval]], [145, 55])
        Ligne2_Col3.setStyle(st_L1C3)
        Ligne2_Col3.setStyle(ts_AGS)
        flow_Col3.append(Ligne2_Col3)
        #
     
        frame = Frame(403.34, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col3, pdf)
     
        # ===============
        # ------- Colonne 4 -------
        # ===============
        flow_Col4 = []
     
        # ------- Ligne 1 -------
        Titre4_1 = Paragraph("Acides Gras Insaturés", style=st_Titre)
        flow_Col4.append(Titre4_1)
     
        # ------- Ligne 2 -------
        # Indice Acides Gras Insaturés
        # C18
        TxT_C18 = []
        TxT_C18 = [['C18H34O3 Ricinoléique']]
        TxTC18 = Table(TxT_C18)
        C18_val = []
        C18_val = [[Liste_Indices_Finaux[15]]]
        C18val = Table(C18_val)
        # O
        TxT_O = []
        TxT_O = [['O  Oléique']]
        TxTO = Table(TxT_O)
        O_val = []
        O_val = [[Liste_Indices_Finaux[16]]]
        Oval = Table(O_val)
        # L
        TxT_L = []
        TxT_L = [['L  Linoléique']]
        TxTL = Table(TxT_L)
        L_val = []
        L_val = [[Liste_Indices_Finaux[17]]]
        Lval = Table(L_val)
        # Ln
        TxT_Ln = []
        TxT_Ln = [['Ln  Linolénique']]
        TxTLn = Table(TxT_Ln)
        Ln_val = []
        Ln_val = [[Liste_Indices_Finaux[18]]]
        Lnval = Table(Ln_val)
     
        ts_AGI = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#FF3399")),
        ])
        st_L2C4 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Ligne2_Col4 = Table([[TxTC18, C18val], [TxTO, Oval], [TxTL, Lval], [TxTLn, Lnval]], [145, 55])
        Ligne2_Col4.setStyle(st_L2C4)
        Ligne2_Col4.setStyle(ts_AGI)
        flow_Col4.append(Ligne2_Col4)
     
        # ------- Ligne 3 -------
        Titre4_2 = Paragraph("<br/>" + "Indices", style=st_Titre)
        flow_Col4.append(Titre4_2)
     
        # ------- Ligne 4 -------
        # # Indice I.N.S
        TxT_Indice_INS = []
        TxT_Indice_INS = [['Indice I.N.S (dureté)']]
        TxTIndiceINS = Table(TxT_Indice_INS)
        Indice_INS_val = []
        Indice_INS_val = [[Liste_Indices_Finaux[4]]]
        IndiceINSval = Table(Indice_INS_val)
     
        # # Indice IODE
        TxT_Indice_IODE = []
        TxT_Indice_IODE = [['Indice IODE (conservation)']]
        TxTIndiceIODE = Table(TxT_Indice_IODE, [133])
        IndiceIODE_val = []
        IndiceIODE_val = [[Liste_Indices_Finaux[5]]]
        IndiceIODEval = Table(IndiceIODE_val, [33])
     
        Ligne4_Col4 = Table([[TxTIndiceINS, IndiceINSval], [TxTIndiceIODE, IndiceIODEval]], [145,55])
        #
        st_L4C4 = TableStyle([
            # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
            # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
            ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
        ])
        Indices = TableStyle([
            ("BACKGROUND", (0, 0), (0, -1), colors.yellow),
        ])
        #
        Ligne4_Col4.setStyle(st_L4C4)
        Ligne4_Col4.setStyle(Indices)
        flow_Col4.append(Ligne4_Col4)
     
        frame = Frame(620.01, 330, 200, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Col4, pdf)
     
        # ==================
        # ------- Ligne Ajouts  --------
        # ==================
        flow_Ligne_Ajouts = []
     
        # ------- Ligne Ajouts -------
        styles = getSampleStyleSheet()
        Titre5_1 = Paragraph("Ajouts sélectionnés", style=st_Titre_Ajouts)
        Titre5_1.underlineWidth=50
        flow_Ligne_Ajouts.append(Titre5_1)
     
        # ------- Sous-ColonneX en 2 lignes -------
        pos_x = [60, 250, 440, 630, 60, 250, 440, 630]                                                # Position en x des 4 ColonneX Ligne 1 et des 4 autres ColonneX Ligne 2
        Largeur_tb = [150, 150, 150, 150, 150, 150, 150, 150]                                     # Largeur TableX
        nb = len(Listes_Ajouts_Full)                                                                            # Nb de type d'ajouts
        # print("nb", nb)
        L1 = [[290,20], [275,37], [255,55], [235,75], [220,90]]                                    # Position et Hauteur Y frame 1 à 4 de la ligne 1 (selon le nb de sélection)
        L2 = [[20], [37], [55], [75], [90]]                                                                   # Hauteur Y frame 1 à 4 de la ligne 2 (selon le nb de sélection)
        Step_Y = [[30], [50], [70], [90], [110]]                                                           # Position Y frame 1 à 4 de la Ligne 2 (selon le nb de sélection)
     
        if nb <= 4:                                                                                                    # Ligne 1  --------------  NbColonne < 4
            # print("Ligne 1  --------------  NbColonne <= 4")
            for i in range(0, nb):
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        if nb > 4:                                                                                                      # Ligne 1  -------------- NbColonne >= 4
            # print("Ligne 1  -------------- NbColonne >= 4")
            for i in range(0, 4):
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    frame = Frame(pos_x[i], L1[max_Ligne1][0], 150, L1[max_Ligne1][1], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        if nb > 4:                                                                                                      # Ligne 2  -------------- NbColonne > 4
            for i in range(4 , nb):
                # print("Ligne 2  -------------- NbColonne > 4")
                # print("i", i)
                Col = "Col" + str(i)
                Col = []
                if len(Listes_Ajouts_Full) != 0:
                    for z in range(0, len(Listes_Ajouts_Full[i])):
                        # print("Listes_Ajouts_Full[", i, "][", z, "]", Listes_Ajouts_Full[i][z])
                        Col.append(Listes_Ajouts_Full[i][z])
                        # print("Col(", i, ")", Col)
                    List_Col = "List_Col" + str(i)
                    tb_Col = "tb_Col" + str(i)
                    tb = "tb" + str(i)
                    # print("Col", Col)
     
                    List_Col = [[z[0]] for z in Col]
                    tb_Col = Table(List_Col)
                    #
                    st_Ajouts = TableStyle([
                        # ("GRID", (0, 0), (-1, -1), 0.25, colors.red),
                        # ("BACKGROUND", (0, 0), (-1, -1), colors.yellow),
                        ('FONTSIZE', (0, 0), (-1, -1), 8),
                        ('FONTNAME', (0, 0), (-1, -1), 'Verdana'),
                        ('ALIGNMENT', (0, 0), (-1, -1), 'LEFT'),
                        ('TOPPADDING', (0, 0), (-1, -1), 0),
                        ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                        ('LEFTPADDING', (0, 0), (-1, -1), 0),
                    ])
                    tb = Table([[tb_Col]], [Largeur_tb[i]])
                    tb.setStyle(st_Ajouts)
                    #
                    flow_Col = "flow_Col" + str(i)
                    flow_Col = []
                    flow_Col.append(tb)
                    frame = "frame" + str(i)
                    # print("L1[max_Ligne1][0] ------------------ ", L1[max_Ligne1][0], "     ",  test[max_Ligne2][0], "      ", (L1[max_Ligne1][0] - test[max_Ligne1][0]))
                    # print("L2[max_Ligne2][0] ------------------ ", L2[max_Ligne2][0])
                    frame = Frame(pos_x[i] , (L1[max_Ligne1][0] - Step_Y[max_Ligne2][0]), 150, L2[max_Ligne2][0], leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
                    frame.addFromList(flow_Col, pdf)
     
        frame = Frame(20, 125, 800, 200, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Ligne_Ajouts, pdf)
     
        # =========================
        # ------- Ligne HV prix manquant  --------
        # =========================
        st_Price = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=8,
            textColor='red'
        )
        flow_Prix = []
     
        HV_wo_Prix = Paragraph("(*) Huiles dont les prix ne sont pas indiqués : " + Liste_HV_wo_Price, style=st_Price)
        flow_Prix.append(HV_wo_Prix)
     
        frame = Frame(20, 100, 723, 20, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_Prix, pdf)
        # ========================
        # ------- Ligne Rappel Sécurité  --------
        # ========================
        # # Colonne 1
        flow_PIC = []
        Retour_Chariot='''<br/><br/>'''
        P_0 = Paragraph(Retour_Chariot, style=st_Titre)
        flow_PIC.append(P_0)
     
        img_SC = Image("ICO\SC.jpg", 50, 71)
        flow_PIC.append(img_SC)
        frame = Frame(20, 20, 80, 100, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=0)
        frame.addFromList(flow_PIC, pdf)
     
        # # Colonne 2
        st_Secure = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='red'
        )
        st_Paragraphe_Secure = ParagraphStyle(
            name='Normal',
            alignment=0,
            leftIndent=24,
            rightIndent=24,
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='black',
            leading=8                                                                                                 # interligne
        )
        st_Link = ParagraphStyle(
            name='Normal',
            fontName='Verdana-Bold',
            fontSize=6,
            textColor='blue',
            leading=8                                                                                                 # interligne
        )
     
        flow_Secure = []
        # ------- Ligne 1 -------
        Titre4_1 = Paragraph("Précautions de sécurité", style=st_Secure)
        flow_Secure.append(Titre4_1)
     
        P_1 = Paragraph("Dans un lieu très bien aéré, lors de la pesée et du mélange (émulsion) de l'eau et la soude caustique, il est impératif de porter des lunettes, des gants de protection néoprène floké coton épaisseur 0.72 (EN374-3 niveau K) puis un masque adéquat." + "<br/>" + "Toujours verser lentement la soude caustique dans l’eau tiède. Utiliser uniquement un fouet et un récipient en inox de préférence. ", style=st_Paragraphe_Secure)
        flow_Secure.append(P_1)
     
        text1='''<br/><a href=https://www.vdp.com/FR/Nieuws/date/desc/1/2269/0/en-374-2016-profond-changement-de-la-norme-relative-aux-gants-resistant-aux-produits-chimiques.html><u>EN 374, la norme relative aux gants résistant aux produits chimiques</u></a>'''
        P_2 = Paragraph(text1, style=st_Link)
        flow_Secure.append(P_2)
     
        text2='''<a href=http://www.inrs.fr/publications/bdd/fichetox/fiche.html?refINRS=FICHETOX_20><u>Hydroxyde de sodium et solutions aqueuses</u></a>'''
        P_3 = Paragraph(text2, style=st_Link)
        flow_Secure.append(P_3)
     
        text3='''<a href=https://www.protecthoms.com/normes-masque-hygiene><u>Protection contre les aérosols solides ou liquides toxiques</u></a>'''
        P_4 = Paragraph(text3, style=st_Link)
        flow_Secure.append(P_4)
     
        frame = Frame(100, 20, 723, 80, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=1)
        frame.addFromList(flow_Secure, pdf)
     
        pdf.save()
     
     
        # ===================
        #        --- Création TxT ---
        # ===================
     
        # r     ouverture en lecture (READ).
        # w     ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé. Si le fichier n'existe pas, il sera créé
        # a     ouverture en mode ajout à la fin du fichier (APPEND). Si le fichier n'existe pas, il sera créé
        # b     ouverture en mode binaire.
        # t     ouverture en mode texte.
        # x     crée un nouveau fichier et l'ouvre pour écriture
     
        # ------- Nom Dossier & Fichier PDF Cible -------
        Nom_File_txt = Nom_Rec.get() + ".txt"
        # print("Nom_File_txt", Nom_File_txt)
        # 1 -- Création du ficher cilbe
        # os.path.join prend un répertoire et un nom de fichier et les concatène pour former un chemin d'accès complet.
        with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
            pass
        # Fermeture du fichier
        file_object.close()
     
        # 2 -- Ecriture Titre Recette
        # L'instruction with garantie la fermeture du fichier en fin de bloc
        # w -- Ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé.
        with open(os.path.join(Dossier_Cible, Nom_File_txt), 'w', encoding='utf-8') as file_object:
            # Ajout 1er. ligne
            file_object.write(Nom_Rec.get() + '\n' + '\n')
        file_object.close()
     
        # 3 -- Ecriture Liste HV Qt Prix INCI SAP
                # - Création d'un tableau type Tuples -
        # exemple : [('Coco Vierge CHAOKOH', 120.0, 1.704, 'Sodium Cocoate'), ('Olive Filipo', 100.0, 0.62, 'Sodium Olivate'), ('Argan-yari', 16.8, 0.551, 'Sodium Arganate'), ('Babassu', 25.63, 0, 'Sodium Babassuate')]
        a = []
        b =[]
        c = []
        d = []
        combs = []
        for u in range(0, len(Liste_Full)):
            a.append(Liste_Full[u][0])
            b.append(str(Liste_Full[u][2]))
            c.append(str(Liste_Full[u][24]))
            d.append(Liste_Full[u][25])
        # print(a, '\n', b, '\n', c)
        for i in range(0, len(a)):
            x = a[i]
            y = b[i]
            z = c[i]
            w = d[i]
            combs.append((x,y,z,w))
        # print("combs", combs, type(combs))
        # print("combs", type(combs))
     
                # - Titre des colonnes -
        columnNames = ("Nom Huile", "Quantité gr.", "Prix", "Nom INCI SAP")
     
                # - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
        columnSizes = [0, 0, 0, 0]
        for column in range(4):
            maxSize = len(columnNames[column])
            for line in combs:
                maxSize = max(len(line[column]), maxSize)
            columnSizes[column] = maxSize
     
                # - Formats des lignes utilisés pour écrire dans le fichier -
                # calcule : +------------+------------+-----------+---------------+
        separatorRow = "+%s+%s+%s+%s+" % ("-" * (columnSizes[0] + 2),
                                          "-" * (columnSizes[1] + 2),
                                          "-" * (columnSizes[2] + 2),
                                          "-" * (columnSizes[3] + 2))
                # calcule : | %-10s | %-10s | %-9s | %13s |
        lineFormat = "| %%-%ds | %%-%ds | %%-%ds | %%%ds |" % (columnSizes[0], columnSizes[1], columnSizes[2], columnSizes[3])
     
                # - Ecriture dans le ficher avec les données formatées -
        try:
            # L'instruction with garantie la fermeture du fichier en fin de bloc
            with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
                print(separatorRow, file=file_object)
                print(lineFormat % columnNames, file=file_object)
                print(separatorRow, file=file_object)
                for mot in combs:
                    # mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
                    print(lineFormat % mot, file=file_object)
                print(separatorRow, file=file_object)
            # print("File generated")
        except IOError as exception:
            print("Cannot write data to file " + str(exception), file=sys.stderr)
     
        file_object.close()
     
        # 4 -- Ecriture Liste Ajouts et une deuxième colonne
               # - Conversion List in List  en une simple List -
        from collections import Iterable
        def flatten(Listes_Ajouts_Full):
            for item in Listes_Ajouts_Full:
                if isinstance(item, Iterable) and not isinstance(item, str):
                    for x in flatten(item):
                        yield x
                else:
                    yield item
        result = list(flatten(Listes_Ajouts_Full))
        # print("list", list, result)                                                                                    # exemple : ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
     
                # - Ajout d'un deuxième paramètre  -
        DP = []
        for i in range(0, len(result)):
            DP.append(result[i])
            DP.append("...")
        # print("DP       ", DP)                                                                                      # exemple : ['Acide Stéarique', '...', 'Acide Palmitique', '...', 'Acide Oléique', '...', 'Acide Myristique', '...', 'Acide Laurique', '...', 'Extrait CO2 de Romarin BIO', '...', 'Vitanime E naturel', '...', 'ARG - Rouge', '...', 'Aloe vera', '...', 'Lait', '...', 'Lait de coco', '...', 'Miel', '...', 'Violette', '...', 'Arbre à thè [Tea Tree]', '...', 'Camomille Romaine', '...', 'Geranium Rosat', '...', 'Hydroxyéthyl Cellulose (HEC)', '...', 'Cacao', '...', 'Café', '...', 'Cannelle', '...', 'Carthame', '...']
     
            # - Construction  simple List par paire -
        a = []
        b = []
        combs = []
        for u in range(0, len(DP), 2):                                                                          # List a pour les nom des Ajouts --> ['Acide Stéarique', 'Acide Palmitique', 'Acide Oléique', 'Acide Myristique', 'Acide Laurique', 'Extrait CO2 de Romarin BIO', 'Vitanime E naturel', 'ARG - Rouge', 'Aloe vera', 'Lait', 'Lait de coco', 'Miel', 'Violette', 'Arbre à thè [Tea Tree]', 'Camomille Romaine', 'Geranium Rosat', 'Hydroxyéthyl Cellulose (HEC)', 'Cacao', 'Café', 'Cannelle', 'Carthame']
            a.append(DP[u])
        for u in range(1, len(DP), 2):                                                                          # List b pour le deuxième paramètre -->  ['...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...', '...']
            b.append(DP[u])
        # print(a, '\n', b)
        for i in range(0, len(a)):
            x = a[i]
            y = b[i]
            combs.append((x,y))
        # print("combs", combs, type(combs))                                                                # [('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...')] <class 'list'>
        # print("combs", type(combs))                                                                           # <class 'list'>
                # - Conversion simple List en Tuple -
        tup = tuple(combs)
        # print("tuple(combs)    ", tup)                                                                           #  (('Acide Stéarique', '...'), ('Acide Palmitique', '...'), ('Acide Oléique', '...'), ('Acide Myristique', '...'), ('Acide Laurique', '...'), ('Extrait CO2 de Romarin BIO', '...'), ('Vitanime E naturel', '...'), ('ARG - Rouge', '...'), ('Aloe vera', '...'), ('Lait', '...'), ('Lait de coco', '...'), ('Miel', '...'), ('Violette', '...'), ('Arbre à thè [Tea Tree]', '...'), ('Camomille Romaine', '...'), ('Geranium Rosat', '...'), ('Hydroxyéthyl Cellulose (HEC)', '...'), ('Cacao', '...'), ('Café', '...'), ('Cannelle', '...'), ('Carthame', '...'))
     
                # - Titre des colonnes -
        columnNames = ("Nom Ajouts", "Quantité gr.")
     
                # - Calcule de la plus longue chaîne de caractères pour chaque colonne du tableau. -
        columnSizes = [0,0]
        for column in range(2):
            maxSize = len(columnNames[column])
            for line in tup:
                maxSize = max(len(line[column]), maxSize)
            columnSizes[column] = maxSize
     
                # - Formats des lignes utilisés pour écrire dans le fichier -
                # calcule : +------------+------------+-----------+---------------+
        separatorRow = "+%s+%s+" % ("-" * (columnSizes[0] +2),
                                                        "-" * (columnSizes[1] + 2))
                # calcule : | %-10s | %-10s | %-9s | %13s |
        lineFormat = "| %%-%ds | %%-%ds |" % \
                     (columnSizes[0], columnSizes[1])
     
                # - Ecriture dans le ficher avec les données formatées -
        try:
            # L'instruction with garantie la fermeture du fichier en fin de bloc
            with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a', encoding='utf-8') as file_object:
                print(separatorRow, file=file_object)
                print(lineFormat % columnNames, file=file_object)
                print(separatorRow, file=file_object)
                for mot in tup:
                    # mot correspond à un tuple de la liste combs --> on peut donc s'en servir avec l'opérateur de formatage
                    print(lineFormat % mot, file=file_object)
                print(separatorRow, file=file_object)
            # print("File generated")
        except IOError as exception:
            print("Cannot write data to file " + str(exception), file=sys.stderr)
     
     
     
        # a -- Ouverture en mode ajout à la fin du fichier (APPEND)
        # with open(os.path.join(Dossier_Cible, Nom_File_txt), 'a') as file_object:
        #     # Ajout texte en fin de fichier
        #     for u in range(0, len(Liste_Full)):
        #         file_object.write(str(Liste_Full[u][0]) + "\t" + "\t" + str(Liste_Full[u][2]) + '\n')
        # file_object.close()
     
     
     
        # Vidange des liste suivantes - cela permet générer à nouveau un PDF (avec ou sans les mêmes ajouts)
        Elements[:] = []
        Element_Ligne1[:] = []
        Element_Ligne2[:] = []
        Listes_Ajouts_Full[:] = []
        Liste_Ajouts1[:] = []
        Liste_Ajouts2[:] = []
        Liste_Ajouts3[:] = []
        Liste_Ajouts4[:] = []
        Liste_Ajouts5[:] = []
        Liste_Ajouts6[:] = []
        Liste_Ajouts7[:] = []
        Liste_Ajouts8[:] = []
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
     
    {
     "version": "auto-py-to-exe-configuration_v1",
     "pyinstallerOptions": [
      {
       "optionDest": "noconfirm",
       "value": true
      },
      {
       "optionDest": "filenames",
       "value": "C:/!TEST!/_TEST_/Compile_7/Main.py"
      },
      {
       "optionDest": "onefile",
       "value": false
      },
      {
       "optionDest": "console",
       "value": false
      },
      {
       "optionDest": "icon_file",
       "value": "C:/!TEST!/_TEST_/Compile_7/ICO/Soap_0.ico"
      },
      {
       "optionDest": "ascii",
       "value": false
      },
      {
       "optionDest": "clean_build",
       "value": false
      },
      {
       "optionDest": "strip",
       "value": false
      },
      {
       "optionDest": "noupx",
       "value": false
      },
      {
       "optionDest": "uac_admin",
       "value": false
      },
      {
       "optionDest": "uac_uiaccess",
       "value": false
      },
      {
       "optionDest": "win_private_assemblies",
       "value": false
      },
      {
       "optionDest": "win_no_prefer_redirects",
       "value": false
      },
      {
       "optionDest": "bootloader_ignore_signals",
       "value": false
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/ICO;.ICO/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DOC;.DOC/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB;.DB/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/Recettes;.Recettes/"
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/AE.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/AG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/ALC.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/AO.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/ARG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/Divers.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/FRAG.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/HE.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/HV.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/Recettes.db;."
      },
      {
       "optionDest": "binaries",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB/TT.db;."
      },
      {
       "optionDest": "hiddenimports",
       "value": "pkg_resources.py2_warn"
      },
      {
       "optionDest": "hookspath",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB"
      },
      {
       "optionDest": "datas",
       "value": "C:/Users/master/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/reportlab/fonts;fonts/"
      }
     ],
     "nonPyinstallerOptions": {
      "increaseRecursionLimit": true,
      "manualArguments": ""
     }
    }

  11. #11
    Invité
    Invité(e)
    Par défaut
    voici votre code que j'ai testé (fonctionne bien même en exe)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
     
    import sys # <= ajout
     
    import os
    import reportlab
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfgen.canvas import Canvas
     
    # modif du calcul du chemin du répertoire "fonts"
    if getattr(sys, 'frozen', False):
        folder = os.path.join(sys._MEIPASS, "fonts") # programma traité par pyinstaller
    else:
        folder = os.path.join(os.path.dirname(reportlab.__file__), 'fonts') # programme non traité
     
     # Police 1
    afmFile = os.path.join(folder, 'DarkGardenMK.afm')
    pfbFile = os.path.join(folder, 'DarkGardenMK.pfb')
    justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
    faceName = 'DarkGardenMK' # pulled from AFM file
    pdfmetrics.registerTypeFace(justFace)
    justFont = pdfmetrics.Font('DarkGardenMK', faceName, 'WinAnsiEncoding')
    pdfmetrics.registerFont(justFont)
     
    # Police 2
    ttfFile = os.path.join(folder, 'Vera.ttf')
    pdfmetrics.registerFont(TTFont("Vera", ttfFile))
     
    # Police 3
    ttfFile = os.path.join(folder, 'Verdanab.ttf')
    pdfmetrics.registerFont(TTFont("Verdana-Bold", ttfFile))
     
     
    # Police 4
    ttfFile = os.path.join(folder, 'arabtype.ttf')
    pdfmetrics.registerFont(TTFont("arabtype", ttfFile))
     
    # Police 5
    ttfFile = os.path.join(folder, 'THSarabun.ttf')
    pdfmetrics.registerFont(TTFont("THSarabun", ttfFile))
     
    # Police 6
    ttfFile = os.path.join(folder, 'THSarabun Bold.ttf')
    pdfmetrics.registerFont(TTFont("THSarabun-Bold", ttfFile))
     
    # Police 7
    ttfFile = os.path.join(folder, 'THSarabun Italic.ttf')
    pdfmetrics.registerFont(TTFont("THSarabun-italic", ttfFile))
     
    # Police 8
    ttfFile = os.path.join(folder, 'THSarabun Bold Italic.ttf')
    pdfmetrics.registerFont(TTFont("THSarabun-BoldItalic", ttfFile))
     
    canvas = Canvas('TestFonts.pdf')
     
    canvas.setFont('DarkGardenMK', 32)
    canvas.drawString(10, 50, '1 - This should be drawn in')
    canvas.drawString(10, 10, 'the font DarkGardenMK')
     
    canvas.setFont('Vera', 32)
    canvas.drawString(10, 150, '2 - This should be drawn in')
    canvas.drawString(10, 100, 'the font Vera')
     
    canvas.setFont('Verdana-Bold', 14)
    canvas.drawString(10, 200, '3 - This should be drawn in')
    canvas.drawString(10, 180, 'the font Verdana-Bold')
     
    canvas.setFont('arabtype', 24)
    canvas.drawString(10, 235, '4 - اختبار الخط العربي')
    canvas.drawString(10, 250, 'the font arabtype')
     
    canvas.setFont('THSarabun', 24)
    canvas.drawString(10, 265, '5 - การทดสอบแบบอักษร THSarabun')
    canvas.drawString(10, 280, 'the font THSarabun')
     
    canvas.setFont('THSarabun-Bold', 24)
    canvas.drawString(10, 320, '6 - การทดสอบแบบอักษร THSarabun')
    canvas.drawString(10, 345, 'the font THSarabun')
     
    canvas.setFont('THSarabun-italic', 24)
    canvas.drawString(10, 365, '7 - การทดสอบแบบอักษร THSarabun')
    canvas.drawString(10, 385, 'the font THSarabun')
     
    canvas.setFont('THSarabun-BoldItalic', 24)
    canvas.drawString(10, 400, '8 - การทดสอบแบบอักษร THSarabun')
    canvas.drawString(10, 435, 'the font THSarabun')
     
    canvas.showPage()
    canvas.save()

  12. #12
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 462
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 462
    Points : 9 249
    Points
    9 249
    Billets dans le blog
    6
    Par défaut
    Juste au cas où: vous parlez du répertoire "Fonts", mais dans le code, c'est "fonts". Je ne crois pas que ça compte sous Windows, mais on ne sait jamais.

    Sinon, pour quelqu'un qui ne connait pas reportlab, j'ai tiré toutes mes cartouches...
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

  13. #13
    Invité
    Invité(e)
    Par défaut
    j'ai trouvé l'erreur

    dans auto-py-to-exe j'ai paramétré comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/ICO;.ICO/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DOC;.DOC/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB;.DB/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/Recettes;.Recettes/"
    en fait, il faut supprimer le .
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/fonts;fonts/"
      }  
    {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/ICO;ICO/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DOC;DOC/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/DB;DB/"
      },
      {
       "optionDest": "datas",
       "value": "C:/!TEST!/_TEST_/Compile_7/Recettes;Recettes/"

  14. #14
    Invité
    Invité(e)
    Par défaut
    maintenant, le soucis est que l'exe à l'aire de fonctionner pour générer le PDf mais rien dans le dossier cible qui est pourtant créé s'il n'existe pas.

  15. #15
    Invité
    Invité(e)
    Par défaut
    en faite le soucis vient de la reconnaissance de l'encodage d'un variable représentant le nom du futur fichier.
    je dois déterminer si la chaîne (variable ) ne contient que des caractères ASCII puis déterminer la langue utilisée.
    j'ai fais ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
        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 qu'une chaîne ne contient que des caractères ASCII?
        i = Nom_Rec.get()
        print("i", Nom_Rec.get())
        NO_ASCII = ""
        try:
            mynewstring = i.encode('ascii')
            flow_Ligne1.append(Paragraph(Nom_Rec.get(), 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":
            from langdetect import detect                                                                         # Détecte la langue d'un texte, d'une variable string
            lang_Nom_Rec = detect(Nom_Rec.get())                                                          # detect la langue utilisée pour le titre
            if lang_Nom_Rec == "th":
                print("th")
                flow_Ligne1.append(Paragraph(Nom_Rec.get(), style=stl_Recette_TH))
                messagebox.askokcancel("ID Langue -TH", "TH")
            elif lang_Nom_Rec == "ar":
                print("ar")
                flow_Ligne1.append(Paragraph(Nom_Rec.get(), style=stl_Recette_AR))
                messagebox.askokcancel("ID Langue -AR", "AR")
     
        frame = Frame(20, 540, 800, 30, showBoundary=0)
        frame.addFromList(flow_Ligne1, pdf)
    cela fonctionne très bien sous pycharm
    par contre une fois la compilation effectuée, avec auto-py-to-exe, seul la variable contenant que du ASCII fonctionne pour générer le futur PDF.

    quelqu'un à rencontre ce problème? merci pour votre temps

Discussions similaires

  1. [Débutant] Deserialisation erreur classe auto-générées (Xsd.exe)
    Par antrax2013 dans le forum C#
    Réponses: 3
    Dernier message: 09/02/2012, 14h17
  2. Clic auto sur un exe
    Par rothuswarrior dans le forum Threads & Processus
    Réponses: 4
    Dernier message: 22/04/2009, 13h08
  3. [vb6] quitter auto l'.exe
    Par totoche dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 01/12/2006, 13h50
  4. 7-Zip - Créer un archive auto-extractible.exe
    Par Edoxituz dans le forum Autres Logiciels
    Réponses: 5
    Dernier message: 29/07/2006, 16h27
  5. auto supprimer un EXE
    Par shainna dans le forum Installation, Déploiement et Sécurité
    Réponses: 5
    Dernier message: 09/11/2005, 12h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo