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
| import os, sys, tempfile, pdfkit
import time # Essai
# Classe recherchant le chemin de wkhtmltopdf.exe sous windows
from config_apsc.capture_chemin_wkhtmltopdf_exe import CaptureWkhtmltopdfWindows
###########################################################
# ESSAI
###########################################################
from PyQt5.QtWidgets import (QProgressBar, QApplication)
from PyQt5.QtCore import (QEventLoop, QTimer)
###########################################################
class Html_vers_pdf_fiche_prof():
def __init__(self, niv_de_classe, nbre_seances, titre_prog, num_seq, incitation, demande, notions_abordees, \
consignes, contraintes, entree_principal_programme, questionnement, que_vont_app_les_elev, \
l_champ_pratiqu_plast, l_question_dens, l_vocabulaire, l_questions, nbre_ref_art, l_ref_art, \
l_comp_et_pts_chiffres, observations, prolongements_possibles, marge_gauche, marge_haute, \
marge_droite, marge_basse, police_normaux_caracteres, police_petits_caracteres, chemin_nom_pdf_final):
super(Html_vers_pdf_fiche_prof, self).__init__()
# Traitement des variables, du code html ...
# Tous les morceaux html sont additionnés pour en faire un seul
self.html_total = html_entete + html_tab_ligne_0 + html_tab_ligne_1 + html_tab_ligne_2 + html_tab_ligne_3 + html_tab_ligne_4 + html_tab_ligne_5 + html_tab_ligne_6 + html_tab_ligne_7 + html_tab_ligne_8 + html_tab_ligne_9 + html_tab_ligne_10 + html_tab_ligne_11 + html_tab_ligne_12 + html_tab_ligne_13 + html_tab_ligne_14 + html_tab_ligne_15 + html_tab_ligne_16 + html_tab_ligne_17 + html_tab_ligne_18 + html_tab_ligne_19 + html_tab_ligne_20 + html_tab_ligne_21 + html_tab_ligne_22 + html_tab_ligne_23 + html_tab_ligne_24 + html_tab_ligne_25 + html_tab_ligne_26 + html_tab_ligne_27 + html_body_html_final
# ...
# Utilisation de pdfkit (donc de wkthmltopdf ---> html vers pdf)
options = {'encoding': 'UTF-8', 'page-size': 'A4', 'orientation':'Portrait', 'footer-right': '[page]', 'footer-line':'', 'footer-font-size':'10', 'footer-spacing':'2', 'footer-left': niv_de_classe+'ème '+titre_prog+' '+'SEQ'+num_seq, 'header-center': 'Séquence réalisée par '+nom_prof+", professeur d'arts plastiques au "+college+', en utilisant '+logiciel_nom+'.', 'header-spacing':'1', 'header-font-size': '7', 'margin-top': str(marge_haute)+'mm', 'margin-left': str(marge_gauche)+'mm', 'margin-right': str(marge_droite)+'mm', 'margin-bottom': str(marge_basse)+'mm'}
# Pas de barre de progression, pour l'instant pour le traitement sous windows
if sys.platform == "win32" :
# Appel de la classe pour rechercher
# whhtmltopdf sous windows
capt = CaptureWkhtmltopdfWindows()
# Recherche du 1er chemin dans la liste
chem_wkhtmltopdf = capt.capture()
# Config
config = pdfkit.configuration(wkhtmltopdf=chem_wkhtmltopdf)
# Exécution
pdfkit.from_string(self.html_total, chemin_nom_pdf_final, configuration=config, options=options)
elif sys.platform == 'linux' :
####################
# ESSAI
####################
# ProgressBar
progress = QProgressBar()
progress.setGeometry(200, 400, 600, 30)
progress.setWindowTitle("Traitement ...")
#
secondes = 15
timer = 0
while (timer < secondes) :
timer = timer + 1
time.sleep(1)
progress.setValue((100*timer)/secondes)
progress.show()
QApplication.processEvents()
#
# Exécution
pdfkit.from_string(self.html_total, chemin_nom_pdf_final, options=options) |
Partager