def __init__(self, dictValeurs={}, dictOptions={}, IDmodele=None, mode="facture", ouverture=True, nomFichier=None, titre=None): """ Impression """ global DICT_VALEURS, DICT_OPTIONS DICT_VALEURS = dictValeurs DICT_OPTIONS = dictOptions self.mode = mode detail = 0 if dictOptions["affichage_prestations"] != None : detail = dictOptions["affichage_prestations"] # Initialisation du document if nomFichier == None : nomDoc = _(u"Temp/%ss_%s.pdf") % (mode, FonctionsPerso.GenerationIDdoc()) else : nomDoc = nomFichier doc = BaseDocTemplate(nomDoc, pagesize=TAILLE_PAGE, showBoundary=False) # Mémorise le ID du modèle modeleDoc = DLG_Noedoc.ModeleDoc(IDmodele=IDmodele) doc.modeleDoc = modeleDoc # Vérifie qu'un cadre principal existe bien dans le document if doc.modeleDoc.FindObjet("cadre_principal") == None : raise Exception("Votre modèle de document doit obligatoirement comporter un cadre principal. Retournez dans l'éditeur de document et utilisez pour votre modèle la commande 'Insérer un objet spécial > Insérer le cadre principal'.") # Importe le template de la première page doc.addPageTemplates(MyPageTemplate(pageSize=TAILLE_PAGE, doc=doc)) story = [] styleSheet = getSampleStyleSheet() h3 = styleSheet['Heading3'] styleTexte = styleSheet['BodyText'] styleTexte.fontName = "Helvetica" styleTexte.fontSize = 9 styleTexte.borderPadding = 9 styleTexte.leading = 12 ## # Définit le template des pages suivantes ## story.append(NextPageTemplate("suivante")) # ----------- Insertion du contenu des frames -------------- listeNomsSansCivilite = [] for IDcompte_payeur, dictValeur in dictValeurs.iteritems() : listeNomsSansCivilite.append((dictValeur["nomSansCivilite"], IDcompte_payeur)) listeNomsSansCivilite.sort() for nomSansCivilite, IDcompte_payeur in listeNomsSansCivilite : dictValeur = dictValeurs[IDcompte_payeur] if dictValeur["select"] == True : story.append(DocAssign("IDcompte_payeur", IDcompte_payeur)) nomSansCivilite = dictValeur["nomSansCivilite"] story.append(Bookmark(nomSansCivilite, str(IDcompte_payeur))) # ------------------- TITRE ----------------- if dictOptions["afficher_titre"] == True : if titre == None : if mode == "facture" : titre = _(u"Facture") if mode == "attestation" : titre = _(u"Attestation de présence") if dictValeur.has_key("texte_titre") : titre = dictValeur["texte_titre"] dataTableau = [] largeursColonnes = [ CADRE_CONTENU[2], ] dataTableau.append((titre,)) texteDateDebut = DateEngFr(str(dictValeur["date_debut"])) texteDateFin = DateEngFr(str(dictValeur["date_fin"])) if dictOptions["afficher_periode"] == True : dataTableau.append((_(u"Période du %s au %s") % (texteDateDebut, texteDateFin),)) styles = [ ('VALIGN', (0,0), (-1,-1), 'MIDDLE'), ('FONT',(0,0),(0,0), "Helvetica-Bold", dictOptions["taille_texte_titre"]), ('LINEBELOW', (0,0), (0,0), 0.25, colors.black), ('ALIGN', (0,0), (-1,-1), 'LEFT'), ] if dictOptions["afficher_periode"] == True : styles.append(('FONT',(0,1),(0,1), "Helvetica", dictOptions["taille_texte_periode"])) tableau = Table(dataTableau, largeursColonnes) tableau.setStyle(TableStyle(styles)) story.append(tableau) story.append(Spacer(0,20)) # TEXTE D'INTRODUCTION pour Attestation ## if mode == "attestation" and dictValeur["intro"] != None : ## texteIntro = dictValeur["intro"] ## paraStyle = ParagraphStyle(name="intro", ## fontName="Helvetica", ## fontSize=9, ## leading=14, ## spaceBefore=0, ## spaceafter=0, ## leftIndent=20, ## rightIndent=20, ## alignment=1, ## ) ## story.append(Paragraph(u"<i>%s</i>" % texteIntro, paraStyle)) ## story.append(Spacer(0,20)) if dictOptions["texte_introduction"] != "" : paraStyle = ParagraphStyle(name="introduction", fontName="Helvetica", fontSize=dictOptions["taille_texte_introduction"], leading=14, spaceBefore=0, spaceafter=0, leftIndent=5, rightIndent=5, alignment=dictOptions["alignement_texte_introduction"], backColor=ConvertCouleurWXpourPDF(dictOptions["couleur_fond_introduction"]), borderColor=ConvertCouleurWXpourPDF(dictOptions["couleur_bord_introduction"]), borderWidth=0.5, borderPadding=5, ) texte = dictValeur["texte_introduction"].replace("\\n", "<br/>") if dictOptions["style_texte_introduction"] == 0 : texte = u"<para>%s</para>" % texte if dictOptions["style_texte_introduction"] == 1 : texte = u"<para><i>%s</i></para>" % texte if dictOptions["style_texte_introduction"] == 2 : texte = u"<para><b>%s</b></para>" % texte if dictOptions["style_texte_introduction"] == 3 : texte = u"<para><i><b>%s</b></i></para>" % texte story.append(Paragraph(texte, paraStyle)) story.append(Spacer(0,20)) couleurFond = ConvertCouleurWXpourPDF(dictOptions["couleur_fond_1"]) # (0.8, 0.8, 1) couleurFondActivite = ConvertCouleurWXpourPDF(dictOptions["couleur_fond_2"]) # (0.92, 0.92, 1) # ------------------- TABLEAU CONTENU ----------------- montantPeriode = FloatToDecimal(0.0) montantVentilation = FloatToDecimal(0.0) # Recherche si TVA utilisée activeTVA = False for IDindividu, dictIndividus in dictValeur["individus"].iteritems() : for IDactivite, dictActivites in dictIndividus["activites"].iteritems() : for date, dictDates in dictActivites["presences"].iteritems() : for dictPrestation in dictDates["unites"] : if dictPrestation["tva"] != None and dictPrestation["tva"] != 0.0 : activeTVA = True # Remplissage for IDindividu, dictIndividus in dictValeur["individus"].iteritems() : if dictIndividus["select"] == True : listeIndexActivites = [] montantPeriode += dictIndividus["total"] montantVentilation += dictIndividus["ventilation"] # Initialisation des largeurs de tableau largeurColonneDate = dictOptions["largeur_colonne_date"] largeurColonneMontantHT = dictOptions["largeur_colonne_montant_ht"] largeurColonneTVA = dictOptions["largeur_colonne_montant_tva"] largeurColonneMontantTTC = dictOptions["largeur_colonne_montant_ttc"] largeurColonneBaseTTC = largeurColonneMontantTTC if activeTVA == True and detail == 0 : largeurColonneIntitule = CADRE_CONTENU[2] - largeurColonneDate - largeurColonneMontantHT - largeurColonneTVA - largeurColonneMontantTTC largeursColonnes = [ largeurColonneDate, largeurColonneIntitule, largeurColonneMontantHT, largeurColonneTVA, largeurColonneMontantTTC] else : if detail != 0 : largeurColonneIntitule = CADRE_CONTENU[2] - largeurColonneDate - largeurColonneBaseTTC - largeurColonneMontantTTC largeursColonnes = [ largeurColonneDate, largeurColonneIntitule, largeurColonneBaseTTC, largeurColonneMontantTTC] else : largeurColonneIntitule = CADRE_CONTENU[2] - largeurColonneDate - largeurColonneMontantTTC largeursColonnes = [ largeurColonneDate, largeurColonneIntitule, largeurColonneMontantTTC] # Insertion du nom de l'individu paraStyle = ParagraphStyle(name="individu", fontName="Helvetica", fontSize=dictOptions["taille_texte_individu"], leading=dictOptions["taille_texte_individu"], spaceBefore=0, spaceafter=0, ) texteIndividu = Paragraph(dictIndividus["texte"], paraStyle) dataTableau = [] dataTableau.append([texteIndividu,]) tableau = Table(dataTableau, [CADRE_CONTENU[2],]) listeStyles = [ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONT', (0, 0), (-1, -1), "Helvetica", dictOptions["taille_texte_individu"]), ('GRID', (0, 0), (-1, -1), 0.25, colors.black), ('BACKGROUND', (0, 0), (-1, 0), couleurFond), ] tableau.setStyle(TableStyle(listeStyles)) story.append(tableau) # Insertion du nom de l'activité for IDactivite, dictActivites in dictIndividus["activites"].iteritems() : texteActivite = dictActivites["texte"] if texteActivite != None : dataTableau = [] dataTableau.append([texteActivite,]) tableau = Table(dataTableau, [CADRE_CONTENU[2],]) listeStyles = [ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONT', (0, 0), (-1, -1), "Helvetica", dictOptions["taille_texte_activite"]), ('GRID', (0, 0), (-1, -1), 0.25, colors.black), ('ALIGN', (0, 0), (-1, -1), 'LEFT'), ('BACKGROUND', (0, 0), (-1, 0), couleurFondActivite), ] tableau.setStyle(TableStyle(listeStyles)) story.append(tableau) # Style de paragraphe normal paraStyle = ParagraphStyle(name="prestation", fontName="Helvetica", fontSize=dictOptions["taille_texte_prestation"], leading=dictOptions["taille_texte_prestation"], spaceBefore=0, spaceAfter=0, ) paraLabelsColonnes = ParagraphStyle(name="paraLabelsColonnes", fontName="Helvetica", fontSize=dictOptions["taille_texte_noms_colonnes"], leading=dictOptions["taille_texte_noms_colonnes"], spaceBefore=0, spaceAfter=0, ) if detail != 0 : # -------------- MODE REGROUPE ---------------- # Regroupement par prestations identiques dictRegroupement = {} for date, dictDates in dictActivites["presences"].iteritems() : total = dictDates["total"] for dictPrestation in dictDates["unites"] : label = dictPrestation["label"] listeDatesUnite = GetDatesListes(dictPrestation["listeDatesConso"]) montant = dictPrestation["montant"] deductions = dictPrestation["deductions"] tva = dictPrestation["tva"] if detail == 1 : labelkey = label if detail == 2 : labelkey = label + " P.U. " + "%.2f %s" % (montant, SYMBOLE) if dictRegroupement.has_key(labelkey) == False : dictRegroupement[labelkey] = {"labelpresta" : label, "total" : 0, "nbre" : 0, "base" : 0, "dates_forfait" : None} dictRegroupement[labelkey]["base"] = montant dictRegroupement[labelkey]["total"] += montant dictRegroupement[labelkey]["nbre"] += 1 if detail == 1 : dictRegroupement[labelkey]["base"] = dictRegroupement[labelkey]["total"] / dictRegroupement[labelkey]["nbre"] if len(listeDatesUnite) > 1 : listeDatesUnite.sort() date_debut = listeDatesUnite[0] date_fin = listeDatesUnite[-1] nbreDates = len(listeDatesUnite) dictRegroupement[labelkey]["dates_forfait"] = _(u"<BR/><font size=5>Du %s au %s soit %d jours</font>") % (DateEngFr(str(date_debut)), DateEngFr(str(date_fin)), nbreDates) # Insertion des prestations regroupées listeLabels = dictRegroupement.keys() listeLabels.sort() dataTableau = [( Paragraph(_(u"<para align='center'>Quantité</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Prestation</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Base</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Montant</para>"), paraLabelsColonnes), ),] for labelkey in listeLabels : label = dictRegroupement[labelkey]["labelpresta"] nbre = dictRegroupement[labelkey]["nbre"] total = dictRegroupement[labelkey]["total"] base = dictRegroupement[labelkey]["base"] # recherche d'un commentaire if dictOptions.has_key("dictCommentaires") : key = (label, IDactivite) if dictOptions["dictCommentaires"].has_key(key) : commentaire = dictOptions["dictCommentaires"][key] label = "%s <i><font color='#939393'>%s</font></i>" % (label, commentaire) # Formatage du label intitule = Paragraph(label, paraStyle) # Rajout des dates de forfait #dates_forfait = dictRegroupement[label]["dates_forfait"] #if dates_forfait != None : # intitule = [intitule, Paragraph(dates_forfait, paraStyle)] dataTableau.append([Paragraph(u"<para align='center'>%d</para>" % nbre, paraStyle), intitule, Paragraph(u"<para align='center'>%.02f %s</para>" % (base, SYMBOLE), paraStyle), Paragraph(u"<para align='center'>%.02f %s</para>" % (total, SYMBOLE), paraStyle)]) else : # -------------------------------------------------------------- MODE DETAILLE ------------------------------------------------------------------ # Insertion de la date listeDates = [] for date, dictDates in dictActivites["presences"].iteritems() : listeDates.append(date) listeDates.sort() paraStyle = ParagraphStyle(name="prestation", fontName="Helvetica", fontSize=dictOptions["taille_texte_prestation"], leading=dictOptions["taille_texte_prestation"], spaceBefore=0, spaceAfter=0, ) dataTableau = [] if activeTVA == True : dataTableau.append([ Paragraph(_(u"<para align='center'>Date</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Prestation</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Montant HT</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Taux TVA</para>"), paraLabelsColonnes), Paragraph(_(u"<para align='center'>Montant TTC</para>"), paraLabelsColonnes), ]) for date in listeDates : dictDates = dictActivites["presences"][date] date = dictDates["texte"] prestations = dictDates["unites"] # Insertion des unités de présence listeIntitules = [] listeMontantsHT = [] listeTVA = [] listeMontantsTTC = [] texteIntitules = u"" texteMontantsHT = u"" texteTVA = u"" texteMontantsTTC = u"" for dictPrestation in prestations : label = dictPrestation["label"] listeDatesUnite = GetDatesListes(dictPrestation["listeDatesConso"]) montant_initial = dictPrestation["montant_initial"] montant = dictPrestation["montant"] deductions = dictPrestation["deductions"] tva = dictPrestation["tva"] # Date texteDate = Paragraph("<para align='center'>%s</para>" % date, paraStyle) # recherche d'un commentaire if dictOptions.has_key("dictCommentaires") : key = (label, IDactivite) if dictOptions["dictCommentaires"].has_key(key) : commentaire = dictOptions["dictCommentaires"][key] label = "%s <i><font color='#939393'>%s</font></i>" % (label, commentaire) # Affiche le Label de la prestation listeIntitules.append(Paragraph(label, paraStyle)) # Recherche si c'est un forfait if len(listeDatesUnite) > 1 : listeDatesUnite.sort() date_debut = listeDatesUnite[0] date_fin = listeDatesUnite[-1] nbreDates = len(listeDatesUnite) label = _(u"<BR/><font size=5>Du %s au %s soit %d jours</font>") % (DateEngFr(str(date_debut)), DateEngFr(str(date_fin)), nbreDates) listeIntitules.append(Paragraph(label, paraStyle)) # TVA if activeTVA == True : if tva == None : tva = 0.0 montantHT = (100.0 * float(montant)) / (100 + float(tva)) #montant - montant * 1.0 * float(tva) / 100 listeMontantsHT.append(Paragraph(u"<para align='center'>%.02f %s</para>" % (montantHT, SYMBOLE), paraStyle)) listeTVA.append(Paragraph(u"<para align='center'>%.02f %%</para>" % tva, paraStyle)) else : listeMontantsHT.append("") listeTVA.append("") # Affiche total listeMontantsTTC.append(Paragraph(u"<para align='center'>%.02f %s</para>" % (montant, SYMBOLE), paraStyle)) # Déductions if len(deductions) > 0 : for dictDeduction in deductions : listeIntitules.append(Paragraph(u"<para align='left'><font size=5 color='#939393'>- %.02f %s : %s</font></para>" % (dictDeduction["montant"], SYMBOLE, dictDeduction["label"]), paraStyle)) #listeIntitules.append(Paragraph(u"<para align='left'><font size=5 color='#939393'>%s</font></para>" % dictDeduction["label"], paraStyle)) listeMontantsHT.append(Paragraph(" ", paraStyle)) listeTVA.append(Paragraph(" ", paraStyle)) listeMontantsTTC.append(Paragraph(" ", paraStyle)) #listeMontantsTTC.append(Paragraph(u"<para align='center'><font size=5 color='#939393'>- %.02f %s</font></para>" % (dictDeduction["montant"], SYMBOLE), paraStyle)) if len(listeIntitules) == 1 : texteIntitules = listeIntitules[0] texteMontantsHT = listeMontantsHT[0] texteTVA = listeTVA[0] texteMontantsTTC = listeMontantsTTC[0] if len(listeIntitules) > 1 : texteIntitules = listeIntitules texteMontantsHT = listeMontantsHT texteTVA = listeTVA texteMontantsTTC = listeMontantsTTC if activeTVA == True : dataTableau.append([texteDate, texteIntitules, texteMontantsHT, texteTVA, texteMontantsTTC]) else : dataTableau.append([texteDate, texteIntitules, texteMontantsTTC]) # Style du tableau des prestations tableau = Table(dataTableau, largeursColonnes) listeStyles = [ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONT', (0, 0), (-1, -1), "Helvetica", dictOptions["taille_texte_prestation"]), ('GRID', (0, 0), (-1,-1), 0.25, colors.black), ('ALIGN', (0, 0), (-1, -1), 'CENTRE'), ('ALIGN', (1, 0), (1, -1), 'LEFT'), ('TOPPADDING', (0, 0), (-1, -1), 1), ('BOTTOMPADDING', (0, 0), (-1, -1), 3), ] tableau.setStyle(TableStyle(listeStyles)) story.append(tableau) # Insertion des totaux dataTableau = [] if activeTVA == True and detail == 0 : dataTableau.append(["", "", "", "", Paragraph("<para align='center'>%.02f %s</para>" % (dictIndividus["total"], SYMBOLE) , paraStyle)]) else : if detail != 0 : dataTableau.append(["", "", "", Paragraph("<para align='center'>%.02f %s</para>" % (dictIndividus["total"], SYMBOLE) , paraStyle)]) else : dataTableau.append(["", "", Paragraph("<para align='center'>%.02f %s</para>" % (dictIndividus["total"], SYMBOLE) , paraStyle)]) listeStyles = [ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONT', (0, 0), (-1, -1), "Helvetica", dictOptions["taille_texte_prestation"]), ('GRID', (-1, -1), (-1,-1), 0.25, colors.black), ('ALIGN', (-1, -1), (-1, -1), 'CENTRE'), ('BACKGROUND', (-1, -1), (-1, -1), couleurFond), ('TOPPADDING', (0, 0), (-1, -1), 1), ('BOTTOMPADDING', (0, 0), (-1, -1), 3), ] # Création du tableau tableau = Table(dataTableau, largeursColonnes) tableau.setStyle(TableStyle(listeStyles)) story.append(tableau) story.append(Spacer(0, 10)) # Intégration des messages, des reports et des qf listeMessages = [] paraStyle = ParagraphStyle(name="message", fontName="Helvetica", fontSize=dictOptions["taille_texte_messages"], leading=dictOptions["taille_texte_messages"], #spaceBefore=0, spaceAfter=2, ) # Date d'échéance ## if dictOptions["echeance"] != None : ## listeMessages.append(Paragraph(dictOptions["echeance"], paraStyle)) # QF aux dates de facture if mode == "facture" and dictOptions["afficher_qf_dates"] == True : dictQfdates = dictValeur["qfdates"] listeDates = dictQfdates.keys() listeDates.sort() if len(listeDates) > 0 : for dates in listeDates : texteQf = _(u"--- Votre QF %s : <b>%s</b> ---") % (dates, dictQfdates[dates]) listeMessages.append(Paragraph(texteQf, paraStyle)) # Reports if mode == "facture" and dictOptions["afficher_impayes"] == True : dictReports = dictValeur["reports"] listePeriodes = dictReports.keys() listePeriodes.sort() if len(listePeriodes) > 0 : texteReport = _(u"<b>Impayés : </b>Merci de bien vouloir nous retourner également le règlement des prestations antérieures : ") for periode in listePeriodes : annee, mois = periode nomPeriode = PeriodeComplete(mois, annee) montant_impaye = dictReports[periode] texteReport += u"%s (%.02f %s), " % (nomPeriode, montant_impaye, SYMBOLE) texteReport = texteReport[:-2] + u"." listeMessages.append(Paragraph(texteReport, paraStyle)) # Messages if mode == "facture" : if dictOptions["afficher_messages"] == True : for message in dictOptions["messages"] : listeMessages.append(Paragraph(message, paraStyle)) for message_familial in dictValeur["messages_familiaux"] : texte = message_familial["texte"] if len(texte) > 0 and texte[-1] not in ".!?" : texte = texte + u"." texte = _(u"<b>Message : </b>%s") % texte listeMessages.append(Paragraph(texte, paraStyle)) if len(listeMessages) > 0 : listeMessages.insert(0, Paragraph(_(u"<u>Informations :</u>"), paraStyle)) # ------------------ CADRE TOTAUX ------------------------ dataTableau = [] largeurColonneLabel = 110 largeursColonnes = [ CADRE_CONTENU[2] - largeurColonneMontantTTC - largeurColonneLabel, largeurColonneLabel, largeurColonneMontantTTC] dataTableau.append((listeMessages, _(u"TOTAL période:"), u"%.02f %s" % (dictValeur["total"], SYMBOLE))) dataTableau.append(("", _(u"Montant déjà réglé :"), u"%.02f %s" % (dictValeur["ventilation"], SYMBOLE))) dataTableau.append(("", _(u"Reste à régler :"), u"%.02f %s" % (dictValeur["solde"], SYMBOLE) )) style = [ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('FONT', (1, 0), (1, -1), "Helvetica-Bold", dictOptions["taille_texte_labels_totaux"]), ('FONT', (2, 0), (2, -1), "Helvetica-Bold", dictOptions["taille_texte_montants_totaux"]), ('GRID', (2, 0), (2, 0), 0.25, colors.black), ('GRID', (2, 1), (2, 1), 0.25, colors.black), ('GRID', (2, 2), (2, 2), 0.25, colors.black), ('ALIGN', (1, 0), (1, -1), 'RIGHT'), ('ALIGN', (2, 0), (2, -1), 'CENTRE'), ('BACKGROUND', (2, 2), (2, 2), couleurFond), ('SPAN', (0, 0), (0, -1)), ] if mode == "facture" and len(listeMessages) > 0 : #style.append( ('BACKGROUND', (0, 0), (0, 0), couleurFondActivite) ) style.append( ('FONT', (0, 0), (0, -1), "Helvetica", 8) ) style.append( ('VALIGN', (0, 0), (0, -1), 'TOP') ) tableau = Table(dataTableau, largeursColonnes, rowHeights=[18, 18, None]) tableau.setStyle(TableStyle(style)) story.append(tableau) # ------------------------- PRELEVEMENTS -------------------- if dictOptions.has_key("afficher_avis_prelevements") and dictValeur.has_key("prelevement") : if dictValeur["prelevement"] != None and dictOptions["afficher_avis_prelevements"] == True : paraStyle = ParagraphStyle(name="intro", fontName="Helvetica", fontSize=8, leading=11, spaceBefore=2, spaceafter=2, alignment=1, backColor=couleurFondActivite, ) story.append(Spacer(0,20)) story.append(Paragraph(u"<para align='center'><i>%s</i></para>" % dictValeur["prelevement"], paraStyle)) # Texte conclusion if dictOptions["texte_conclusion"] != "" : story.append(Spacer(0,20)) paraStyle = ParagraphStyle(name="conclusion", fontName="Helvetica", fontSize=dictOptions["taille_texte_conclusion"], leading=14, spaceBefore=0, spaceafter=0, leftIndent=5, rightIndent=5, alignment=dictOptions["alignement_texte_conclusion"], backColor=ConvertCouleurWXpourPDF(dictOptions["couleur_fond_conclusion"]), borderColor=ConvertCouleurWXpourPDF(dictOptions["couleur_bord_conclusion"]), borderWidth=0.5, borderPadding=5, ) texte = dictValeur["texte_conclusion"].replace("\\n", "<br/>") if dictOptions["style_texte_conclusion"] == 0 : texte = u"<para>%s</para>" % texte if dictOptions["style_texte_conclusion"] == 1 : texte = u"<para><i>%s</i></para>" % texte if dictOptions["style_texte_conclusion"] == 2 : texte = u"<para><b>%s</b></para>" % texte if dictOptions["style_texte_conclusion"] == 3 : texte = u"<para><i><b>%s</b></i></para>" % texte story.append(Paragraph(texte, paraStyle)) # Image signature if dictOptions["image_signature"] != "" : cheminImage = dictOptions["image_signature"] if os.path.isfile(cheminImage) : img = Image(cheminImage) largeur, hauteur = int(img.drawWidth * 1.0 * dictOptions["taille_image_signature"] / 100.0), int(img.drawHeight * 1.0 * dictOptions["taille_image_signature"] / 100.0) if largeur > CADRE_CONTENU[2] or hauteur > CADRE_CONTENU[3] : raise Exception(_(u"L'image de signature est trop grande. Veuillez diminuer sa taille avec le parametre Taille.")) img.drawWidth, img.drawHeight = largeur, hauteur if dictOptions["alignement_image_signature"] == 0 : img.hAlign = "LEFT" if dictOptions["alignement_image_signature"] == 1 : img.hAlign = "CENTER" if dictOptions["alignement_image_signature"] == 2 : img.hAlign = "RIGHT" story.append(Spacer(0,20)) story.append(img) # Saut de page story.append(PageBreak()) # Finalisation du PDF ## try : doc.build(story) ## except Exception, err : ## print "Erreur dans ouverture PDF :", err ## if "Permission denied" in err : ## dlg = wx.MessageDialog(None, _(u"Noethys ne peut pas créer le PDF.\n\nVeuillez vérifier qu'un autre PDF n'est pas déjà ouvert en arrière-plan..."), _(u"Erreur d'édition"), wx.OK | wx.ICON_ERROR) ## dlg.ShowModal() ## dlg.Destroy() ## return # Ouverture du PDF if ouverture == True : FonctionsPerso.LanceFichierExterne(nomDoc)
def old_tables_test(): from reportlab.lib.units import inch, cm from reportlab.platypus.flowables import Image, PageBreak, Spacer, XBox from reportlab.platypus.paragraph import Paragraph from reportlab.platypus.xpreformatted import XPreformatted from reportlab.platypus.flowables import Preformatted from reportlab.platypus.doctemplate import SimpleDocTemplate from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.platypus.tables import GRID_STYLE, BOX_STYLE, LABELED_GRID_STYLE, COLORED_GRID_STYLE, LIST_STYLE, LongTable rowheights = (24, 16, 16, 16, 16) rowheights2 = (24, 16, 16, 16, 30) colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) data = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) data2 = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) lst = [] lst.append(Paragraph("Tables", styleSheet['Heading1'])) lst.append(Paragraph(__doc__, styleSheet['BodyText'])) lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) lst.append(Preformatted(""" colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) rowheights = (24, 16, 16, 16, 16) data = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) t = Table(data, colwidths, rowheights) """, styleSheet['Code'], dedent=4)) lst.append(Paragraph(""" You can then give the Table a TableStyle object to control its format. The first TableStyle used was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" GRID_STYLE = TableStyle( [('GRID', (0,0), (-1,-1), 0.25, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) lst.append(Paragraph(""" TableStyles are created by passing in a list of commands. There are two types of commands - line commands and cell formatting commands. In all cases, the first three elements of a command are the command name, the starting cell and the ending cell. """, styleSheet['BodyText'])) lst.append(Paragraph(""" Line commands always follow this with the weight and color of the desired lines. Colors can be names, or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and INNERGRID. """, styleSheet['BodyText'])) lst.append(Paragraph(""" Cell formatting commands are: """, styleSheet['BodyText'])) lst.append(Paragraph(""" FONT - takes fontname, fontsize and (optional) leading. """, styleSheet['Definition'])) lst.append(Paragraph(""" TEXTCOLOR - takes a color name or (R,G,B) tuple. """, styleSheet['Definition'])) lst.append(Paragraph(""" ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT, CENTRE (or CENTER) or DECIMAL. """, styleSheet['Definition'])) lst.append(Paragraph(""" LEFTPADDING - defaults to 6. """, styleSheet['Definition'])) lst.append(Paragraph(""" RIGHTPADDING - defaults to 6. """, styleSheet['Definition'])) lst.append(Paragraph(""" BOTTOMPADDING - defaults to 3. """, styleSheet['Definition'])) lst.append(Paragraph(""" A tablestyle is applied to a table by calling Table.setStyle(tablestyle). """, styleSheet['BodyText'])) t = Table(data, colwidths, rowheights) t.setStyle(GRID_STYLE) lst.append(PageBreak()) lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) t = Table(data, colwidths, rowheights) t.setStyle(BOX_STYLE) lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" BOX_STYLE = TableStyle( [('BOX', (0,0), (-1,-1), 0.50, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) t.setStyle(LABELED_GRID_STYLE) lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) t = Table(data2, colwidths, rowheights2) t.setStyle(LABELED_GRID_STYLE) lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" LABELED_GRID_STYLE = TableStyle( [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 2, colors.black), ('LINEBELOW', (0,0), (-1,0), 2, colors.black), ('LINEAFTER', (0,0), (0,-1), 2, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) lst.append(PageBreak()) t = Table(data, colwidths, rowheights) t.setStyle(COLORED_GRID_STYLE) lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" COLORED_GRID_STYLE = TableStyle( [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 2, colors.red), ('LINEBELOW', (0,0), (-1,0), 2, colors.black), ('LINEAFTER', (0,0), (0,-1), 2, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) t.setStyle(LIST_STYLE) lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" LIST_STYLE = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) ts = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), ('ALIGN', (1,1), (-1,-1), 'RIGHT'), ('TEXTCOLOR', (0,1), (0,-1), colors.red), ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] ) t.setStyle(ts) lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" ts = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), ('ALIGN', (1,1), (-1,-1), 'RIGHT'), ('TEXTCOLOR', (0,1), (0,-1), colors.red), ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] ) """, styleSheet['Code'])) data = ( ('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) c = list(colwidths) c[0] = None c[8] = None t = Table(data, c, [None]+list(rowheights[1:])) t.setStyle(LIST_STYLE) lst.append(Paragraph(""" This is a LIST_STYLE table with the first rowheight set to None ie automatic. The top row cells are split at a newline '\\n' character. The first and August column widths were also set to None. """, styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" This demonstrates a number of features useful in financial statements. The first is decimal alignment; with ALIGN=DECIMAL the numbers align on the points; and the points are aligned based on the RIGHTPADDING, which is usually 3 points so you should set it higher. The second is multiple lines; one can specify double or triple lines and control the separation if desired. Finally, the coloured negative numbers were (we regret to say) done in the style; we don't have a way to conditionally format numbers based on value yet. """, styleSheet['BodyText'])) t = Table([['Corporate Assets','Amount'], ['Fixed Assets','1,234,567.89'], ['Company Vehicle','1,234.8901'], ['Petty Cash','42'], [u'Intellectual Property\u00ae','(42,078,231.56)'], ['Overdraft','(12,345)'], ['Boardroom Flat Screen','60 inches'], ['Net Position','Deep Sh*t.Really'] ], [144,72]) ts = TableStyle( [#first the top row ('ALIGN', (1,1), (-1,-1), 'CENTER'), ('LINEABOVE', (0,0), (-1,0), 1, colors.purple), ('LINEBELOW', (0,0), (-1,0), 1, colors.purple), ('FONT', (0,0), (-1,0), 'Times-Bold'), #bottom row has a line above, and two lines below ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple), #last 2 are count, sep ('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None, None, 4,1), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.red), ('FONT', (0,-1), (-1,-1), 'Times-Bold'), #numbers column ('ALIGN', (1,1), (-1,-1), 'DECIMAL'), ('RIGHTPADDING', (1,1), (-1,-1), 36), ('TEXTCOLOR', (1,4), (1,4), colors.red), #red cell ] ) t.setStyle(ts) lst.append(t) lst.append(Spacer(36,36)) lst.append(Paragraph(""" The red numbers should be aligned LEFT & BOTTOM, the blue RIGHT & TOP and the green CENTER & MIDDLE. """, styleSheet['BodyText'])) XY = [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'], ['X10y', 'X11y', 'X12y', 'X13y', 'X14y'], ['X20y', 'X21y', 'X22y', 'X23y', 'X24y'], ['X30y', 'X31y', 'X32y', 'X33y', 'X34y']] t=Table(XY, 5*[0.6*inch], 4*[0.6*inch]) t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'), ('TEXTCOLOR',(1,1),(-2,-2),colors.red), ('VALIGN',(0,0),(1,-1),'TOP'), ('ALIGN',(0,0),(1,-1),'RIGHT'), ('TEXTCOLOR',(0,0),(1,-1),colors.blue), ('ALIGN',(0,-1),(-1,-1),'CENTER'), ('VALIGN',(0,-1),(-1,-1),'MIDDLE'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.green), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ]) lst.append(t) data = [('alignment', 'align\012alignment'), ('bulletColor', 'bulletcolor\012bcolor'), ('bulletFontName', 'bfont\012bulletfontname'), ('bulletFontSize', 'bfontsize\012bulletfontsize'), ('bulletIndent', 'bindent\012bulletindent'), ('firstLineIndent', 'findent\012firstlineindent'), ('fontName', 'face\012fontname\012font'), ('fontSize', 'size\012fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent\012lindent'), ('rightIndent', 'rightindent\012rindent'), ('spaceAfter', 'spaceafter\012spacea'), ('spaceBefore', 'spacebefore\012spaceb'), ('textColor', 'fg\012textcolor\012color')] t = Table(data) t.setStyle([ ('VALIGN',(0,0),(-1,-1),'TOP'), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ]) lst.append(t) t = Table([ ('Attribute', 'Synonyms'), ('alignment', 'align, alignment'), ('bulletColor', 'bulletcolor, bcolor'), ('bulletFontName', 'bfont, bulletfontname'), ('bulletFontSize', 'bfontsize, bulletfontsize'), ('bulletIndent', 'bindent, bulletindent'), ('firstLineIndent', 'findent, firstlineindent'), ('fontName', 'face, fontname, font'), ('fontSize', 'size, fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent, lindent'), ('rightIndent', 'rightindent, rindent'), ('spaceAfter', 'spaceafter, spacea'), ('spaceBefore', 'spacebefore, spaceb'), ('textColor', 'fg, textcolor, color')]) t.repeatRows = 1 t.setStyle([ ('FONT',(0,0),(-1,1),'Times-Bold',10,12), ('FONT',(0,1),(-1,-1),'Courier',8,8), ('VALIGN',(0,0),(-1,-1),'MIDDLE'), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ('BACKGROUND', (0, 0), (-1, 0), colors.green), ('BACKGROUND', (0, 1), (-1, -1), colors.pink), ('ALIGN', (0, 0), (-1, 0), 'CENTER'), ('ALIGN', (0, 1), (0, -1), 'LEFT'), ('ALIGN', (-1, 1), (-1, -1), 'RIGHT'), ('FONT', (0, 0), (-1, 0), 'Times-Bold', 12), ('ALIGN', (1, 1), (1, -1), 'CENTER'), ]) lst.append(t) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 5,6), ('GRID', (0,0), (-1,-1), 0.25, colors.blue),])) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 10,12), ('GRID', (0,0), (-1,-1), 0.25, colors.black),])) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 20,24), ('GRID', (0,0), (-1,-1), 0.25, colors.red),])) lst.append(PageBreak()) data= [['00', '01', '02', '03', '04'], ['10', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34']] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('BACKGROUND', (1, 1), (1, 2), colors.lavender), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('TEXTCOLOR',(0,-1),(-2,-1),colors.green), ]) lst.append(Paragraph("Illustrating splits: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: repeated split(4in,30)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) S = t.split(4*inch,30) s = S.pop(-1) S.extend(s.split(4*inch,30)) s = S.pop(-1) S.extend(s.split(4*inch,30)) for s in S: lst.append(s) lst.append(Spacer(0,6)) lst.append(PageBreak()) data= [['00', '01', '02', '03', '04'], ['', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '', '33', '34']] sty=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('SPAN',(2,2),(2,3)), ] t=Table(data,style=sty) lst.append(Paragraph("Illustrating splits with spans: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) data= [['00', '01', '02', '03', '04'], ['', '11', '12', '13', ''], ['20', '21', '22', '23', '24'], ['30', '31', '', '33', ''], ['40', '41', '', '43', '44']] sty=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND',(-2,1),(-1,1),colors.palegreen), ('SPAN',(-2,1),(-1,1)), ('BACKGROUND',(-2,3),(-1,3),colors.yellow), ('SPAN',(-2,3),(-1,3)), ('BACKGROUND', (2, 3), (2, 4), colors.orange), ('SPAN',(2,3),(2,4)), ] t=Table(data,style=sty,repeatRows=2) lst.append(Paragraph("Illustrating splits with spans and repeatRows: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) if 1: lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) lst.append(PageBreak()) from reportlab.lib.testutils import testsFolder I = Image(os.path.join(os.path.dirname(testsFolder),'tools','pythonpoint','demos','leftlogo.gif')) I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth I.drawWidth = 1.25*inch #I.drawWidth = 9.25*inch #uncomment to see better messaging P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"]) B = TableBarChart() BP = Paragraph("<para align=center spaceb=3>A bar chart in a cell.</para>", styleSheet["BodyText"]) data= [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'], ['00', '01', '02', [I,P], '04'], ['10', '11', '12', [I,P], '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34'], ['40', '41', '42', [B,BP], '44']] t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('BACKGROUND', (1, 1), (1, 2), colors.lavender), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('BOX',(0,0),(-1,-1),2,colors.black), ('GRID',(0,0),(-1,-1),0.5,colors.black), ('VALIGN',(3,0),(3,0),'BOTTOM'), ('BACKGROUND',(3,0),(3,0),colors.limegreen), ('BACKGROUND',(3,1),(3,1),colors.khaki), ('ALIGN',(3,1),(3,1),'CENTER'), ('BACKGROUND',(3,2),(3,2),colors.beige), ('ALIGN',(3,2),(3,2),'LEFT'), ]) t._argW[3]=1.5*inch lst.append(t) # now for an attempt at column spanning. lst.append(PageBreak()) data= [['A', 'BBBBB', 'C', 'D', 'E'], ['00', '01', '02', '03', '04'], ['10', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34']] sty = [ ('ALIGN',(0,0),(-1,-1),'CENTER'), ('VALIGN',(0,0),(-1,-1),'TOP'), ('GRID',(0,0),(-1,-1),1,colors.green), ('BOX',(0,0),(-1,-1),2,colors.red), #span 'BBBB' across middle 3 cells in top row ('SPAN',(1,0),(3,0)), #now color the first cell in this range only, #i.e. the one we want to have spanned. Hopefuly #the range of 3 will come out khaki. ('BACKGROUND',(1,0),(1,0),colors.khaki), ('SPAN',(0,2),(-1,2)), #span 'AAA'down entire left column ('SPAN',(0,0), (0, 1)), ('BACKGROUND',(0,0),(0,0),colors.cyan), ('TEXTCOLOR', (0,'splitfirst'), (-1,'splitfirst'), colors.cyan), ('TEXTCOLOR', (0,'splitlast'), (-1,'splitlast'), colors.red), ('BACKGROUND', (0,'splitlast'), (-1,'splitlast'), colors.pink), ('LINEBELOW', (0,'splitlast'), (-1,'splitlast'), 1, colors.grey,'butt'), ] t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5) lst.append(t) lst.append(Spacer(18,18)) t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5) for s in t.split(4*inch,72): lst.append(s) lst.append(Spacer(0,6)) # now for an attempt at percentage widths lst.append(Spacer(18,18)) lst.append(Paragraph("This table has colWidths=5*['14%']!", styleSheet['BodyText'])) t=Table(data,style=sty, colWidths = ['14%'] * 5, rowHeights = [20]*5) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph("This table has colWidths=['14%','10%','19%','22%','*']!", styleSheet['BodyText'])) t=Table(data,style=sty, colWidths = ['14%','10%','19%','22%','*'], rowHeights = [20]*5) lst.append(t) # Mike's test example lst.append(Spacer(18,18)) lst.append(Paragraph('Mike\'s Spanning Example', styleSheet['Heading1'])) data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], [Paragraph('World <font color="green">Domination</font>: The First Five Years', styleSheet['BodyText']),''], [Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], ] t=Table(data, style=[('SPAN',(0,0),(1,0)),('SPAN',(0,1),(1,1)),('SPAN',(0,2),(1,2)),], colWidths = [3*cm,8*cm], rowHeights = [None]*3) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph('Mike\'s Non-spanning Example', styleSheet['Heading1'])) data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], [Paragraph('World <font color="magenta">Domination</font>: The First Five Years', styleSheet['BodyText'])], [Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], ] t=Table(data, style=[], colWidths = [11*cm], rowHeights = [None]*3) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph('xpre example', styleSheet['Heading1'])) data= [ [ XPreformatted('Account Details', styleSheet['Heading3']), '', XPreformatted('Client Details', styleSheet['Heading3']), ], #end of row 0 ] t=Table(data, style=[], colWidths = [80,230.0,80], rowHeights = [None]*1) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph('Trying colour cycling in background', styleSheet['Heading1'])) lst.append(Paragraph("This should alternate pale blue and uncolored by row", styleSheet['BodyText'])) data= [['001', '01', '02', '03', '04', '05'], ['002', '01', '02', '03', '04', '05'], ['003', '01', '02', '03', '04', '05'], ['004', '01', '02', '03', '04', '05'], ['005', '01', '02', '03', '04', '05'], ['006', '01', '02', '03', '04', '05'], ['007', '01', '02', '03', '04', '05'], ['008', '01', '02', '03', '04', '05'], ['009', '01', '02', '03', '04', '05'], ['010', '01', '02', '03', '04', '05'], ] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('ROWBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, None)), ]) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("And this should pale blue, pale pink and None by column", styleSheet['BodyText'])) data= [['001', '01', '02', '03', '04', '05'], ['002', '01', '02', '03', '04', '05'], ['003', '01', '02', '03', '04', '05'], ['004', '01', '02', '03', '04', '05'], ['005', '01', '02', '03', '04', '05'], ['006', '01', '02', '03', '04', '05'], ['007', '01', '02', '03', '04', '05'], ['008', '01', '02', '03', '04', '05'], ['009', '01', '02', '03', '04', '05'], ['010', '01', '02', '03', '04', '05'], ] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('COLBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, 0xFFD0D0, None)), ]) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph("This spanning example illustrates automatic removal of grids and lines in spanned cells!", styleSheet['BodyText'])) lst.append(Spacer(0,6)) data= [['Top\nLeft', '', '02', '03', '04', '05', '06', '07'], ['', '', '12', 'Span (3,1) (6,2)', '','','','17'], ['20', '21', '22', '', '','','','27'], ['30', '31', '32', '33', '34','35','36','37'], ['40', 'In The\nMiddle', '', '', '44','45','46','47'], ['50', '', '', '', '54','55','56','57'], ['60', '', '', '','64', '65', 'Bottom\nRight', ''], ['70', '71', '72', '73','74', '75', '', '']] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('BACKGROUND',(0,0),(1,1),colors.palegreen), ('SPAN',(0,0),(1,1)), ('BACKGROUND',(-2,-2),(-1,-1), colors.pink), ('SPAN',(-2,-2),(-1,-1)), ('SPAN',(1,4),(3,6)), ('BACKGROUND',(1,4),(3,6), colors.lightblue), ('SPAN',(3,1),(6,2)), ('BACKGROUND',(3,1),(6,2), colors.peachpuff), ('VALIGN',(3,1),(6,2),'TOP'), ('LINEABOVE', (0,2),(-1,2), 1, colors.black, 0, None, None, 2, 2), ('LINEBEFORE', (3,0),(3,-1), 1, colors.black, 0, None, None, 2, 2), ]) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph("und jetzt noch eine Tabelle mit 5000 Zeilen:", styleSheet['BodyText'])) sty = [ ('GRID',(0,0),(-1,-1),1,colors.green), ('BOX',(0,0),(-1,-1),2,colors.red), ] data = [[str(i), Paragraph("xx "* (i%10), styleSheet["BodyText"]), Paragraph("blah "*(i%40), styleSheet["BodyText"])] for i in range(500)] t=LongTable(data, style=sty, colWidths = [50,100,200]) lst.append(t) #Yuan Hong's bug tester lst.append(PageBreak()) lst.append(Paragraph('Yian Hong\'s Bug Case (should not blow up)', styleSheet['Heading2'])) data = ([['Col1', 'Col2', 'Col3', 'Col4', 'Col5']]+ [['01', Paragraph('This is cell one that contains a paragraph.', styleSheet['Normal']), '02', '03', '04'] for i in range(50)]) t = Table(data, ['20%']*5, repeatRows=1) t.setStyle(TableStyle([ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ('SPAN', (0,50), (-2,50)), ])) lst.append(t) lst.append(PageBreak()) #Volker Haas' example extended #the optimal row heights are the solution of an LP similar to # #Objective function # min: 3*h0+3*h1+3*h2+2*h3; # #constraints # h0>=12; # h1>=12; # h2>=12; # h3>=12; # h0+h1+h2>=48; # h0+h1>=12; # h2+h3>=60; # #the solution H=[12,12,24,36] def makeTable(x,y): return Table([ ['00', '01', '02', '03', '04', '05\nline2\nline3\nline4'], ['', '11', '12', x, '',''], ['20', '21', y, '23', '24',''], ['30', '31', '', '33', '34','35'], ], style=[ ('TOPPADDING',(0,0),(-1,-1),0), ('BOTTOMPADDING',(0,0),(-1,-1),0), ('RIGHTPADDING',(0,0),(-1,-1),0), ('LEFTPADDING',(0,0),(-1,-1),0), ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('SPAN',(2,2),(2,3)), ('SPAN',(3,1),(4,1)), ('SPAN',(5,0),(5,2)), ]) p_style= ParagraphStyle('Normal') lst.append(makeTable( Paragraph('This is a string',p_style), Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) lst.append(Spacer(10,10)) lst.append(makeTable( XPreformatted('This is a string',p_style), Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) lst.append(Spacer(10,10)) lst.append(makeTable( 'This is a string', '22\nblub\nasfd\nafd\nasdfs', )) lst.append(Spacer(10,10)) lst.append(makeTable( 'This is a string', Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) SimpleDocTemplate(outputfile('test_platypus_tables_2.pdf'), showBoundary=1).build(lst)
def old_tables_test(): from reportlab.lib.units import inch, cm from reportlab.platypus.flowables import Image, PageBreak, Spacer, XBox from reportlab.platypus.paragraph import Paragraph from reportlab.platypus.xpreformatted import XPreformatted from reportlab.platypus.flowables import Preformatted from reportlab.platypus.doctemplate import SimpleDocTemplate from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.platypus.tables import GRID_STYLE, BOX_STYLE, LABELED_GRID_STYLE, COLORED_GRID_STYLE, LIST_STYLE, LongTable rowheights = (24, 16, 16, 16, 16) rowheights2 = (24, 16, 16, 16, 30) colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) data = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) data2 = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) lst = [] lst.append(Paragraph("Tables", styleSheet['Heading1'])) lst.append(Paragraph(__doc__, styleSheet['BodyText'])) lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) lst.append(Preformatted(""" colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) rowheights = (24, 16, 16, 16, 16) data = ( ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) t = Table(data, colwidths, rowheights) """, styleSheet['Code'], dedent=4)) lst.append(Paragraph(""" You can then give the Table a TableStyle object to control its format. The first TableStyle used was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" GRID_STYLE = TableStyle( [('GRID', (0,0), (-1,-1), 0.25, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) lst.append(Paragraph(""" TableStyles are created by passing in a list of commands. There are two types of commands - line commands and cell formatting commands. In all cases, the first three elements of a command are the command name, the starting cell and the ending cell. """, styleSheet['BodyText'])) lst.append(Paragraph(""" Line commands always follow this with the weight and color of the desired lines. Colors can be names, or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and INNERGRID. """, styleSheet['BodyText'])) lst.append(Paragraph(""" Cell formatting commands are: """, styleSheet['BodyText'])) lst.append(Paragraph(""" FONT - takes fontname, fontsize and (optional) leading. """, styleSheet['Definition'])) lst.append(Paragraph(""" TEXTCOLOR - takes a color name or (R,G,B) tuple. """, styleSheet['Definition'])) lst.append(Paragraph(""" ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT, CENTRE (or CENTER) or DECIMAL. """, styleSheet['Definition'])) lst.append(Paragraph(""" LEFTPADDING - defaults to 6. """, styleSheet['Definition'])) lst.append(Paragraph(""" RIGHTPADDING - defaults to 6. """, styleSheet['Definition'])) lst.append(Paragraph(""" BOTTOMPADDING - defaults to 3. """, styleSheet['Definition'])) lst.append(Paragraph(""" A tablestyle is applied to a table by calling Table.setStyle(tablestyle). """, styleSheet['BodyText'])) t = Table(data, colwidths, rowheights) t.setStyle(GRID_STYLE) lst.append(PageBreak()) lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) t = Table(data, colwidths, rowheights) t.setStyle(BOX_STYLE) lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" BOX_STYLE = TableStyle( [('BOX', (0,0), (-1,-1), 0.50, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) t.setStyle(LABELED_GRID_STYLE) lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) t = Table(data2, colwidths, rowheights2) t.setStyle(LABELED_GRID_STYLE) lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" LABELED_GRID_STYLE = TableStyle( [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 2, colors.black), ('LINEBELOW', (0,0), (-1,0), 2, colors.black), ('LINEAFTER', (0,0), (0,-1), 2, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) lst.append(PageBreak()) t = Table(data, colwidths, rowheights) t.setStyle(COLORED_GRID_STYLE) lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" COLORED_GRID_STYLE = TableStyle( [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 2, colors.red), ('LINEBELOW', (0,0), (-1,0), 2, colors.black), ('LINEAFTER', (0,0), (0,-1), 2, colors.black), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) t.setStyle(LIST_STYLE) lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" LIST_STYLE = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), ('ALIGN', (1,1), (-1,-1), 'RIGHT')] ) """, styleSheet['Code'])) t = Table(data, colwidths, rowheights) ts = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), ('ALIGN', (1,1), (-1,-1), 'RIGHT'), ('TEXTCOLOR', (0,1), (0,-1), colors.red), ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] ) t.setStyle(ts) lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" It was created as follows: """, styleSheet['BodyText'])) lst.append(Preformatted(""" ts = TableStyle( [('LINEABOVE', (0,0), (-1,0), 2, colors.green), ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), ('ALIGN', (1,1), (-1,-1), 'RIGHT'), ('TEXTCOLOR', (0,1), (0,-1), colors.red), ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] ) """, styleSheet['Code'])) data = ( ('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'), ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') ) c = list(colwidths) c[0] = None c[8] = None t = Table(data, c, [None]+list(rowheights[1:])) t.setStyle(LIST_STYLE) lst.append(Paragraph(""" This is a LIST_STYLE table with the first rowheight set to None ie automatic. The top row cells are split at a newline '\\n' character. The first and August column widths were also set to None. """, styleSheet['BodyText'])) lst.append(t) lst.append(Paragraph(""" This demonstrates a number of features useful in financial statements. The first is decimal alignment; with ALIGN=DECIMAL the numbers align on the points; and the points are aligned based on the RIGHTPADDING, which is usually 3 points so you should set it higher. The second is multiple lines; one can specify double or triple lines and control the separation if desired. Finally, the coloured negative numbers were (we regret to say) done in the style; we don't have a way to conditionally format numbers based on value yet. """, styleSheet['BodyText'])) t = Table([[u'Corporate Assets','Amount'], ['Fixed Assets','1,234,567.89'], ['Company Vehicle','1,234.8901'], ['Petty Cash','42'], [u'Intellectual Property\u00ae','(42,078,231.56)'], ['Overdraft','(12,345)'], ['Boardroom Flat Screen','60 inches'], ['Net Position','Deep Sh*t.Really'] ], [144,72]) ts = TableStyle( [#first the top row ('ALIGN', (1,1), (-1,-1), 'CENTER'), ('LINEABOVE', (0,0), (-1,0), 1, colors.purple), ('LINEBELOW', (0,0), (-1,0), 1, colors.purple), ('FONT', (0,0), (-1,0), 'Times-Bold'), #bottom row has a line above, and two lines below ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple), #last 2 are count, sep ('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None, None, 4,1), ('LINEBELOW', (0,-1), (-1,-1), 1, colors.red), ('FONT', (0,-1), (-1,-1), 'Times-Bold'), #numbers column ('ALIGN', (1,1), (-1,-1), 'DECIMAL'), ('RIGHTPADDING', (1,1), (-1,-1), 36), ('TEXTCOLOR', (1,4), (1,4), colors.red), #red cell ] ) t.setStyle(ts) lst.append(t) lst.append(Spacer(36,36)) lst.append(Paragraph(""" The red numbers should be aligned LEFT & BOTTOM, the blue RIGHT & TOP and the green CENTER & MIDDLE. """, styleSheet['BodyText'])) XY = [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'], ['X10y', 'X11y', 'X12y', 'X13y', 'X14y'], ['X20y', 'X21y', 'X22y', 'X23y', 'X24y'], ['X30y', 'X31y', 'X32y', 'X33y', 'X34y']] t=Table(XY, 5*[0.6*inch], 4*[0.6*inch]) t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'), ('TEXTCOLOR',(1,1),(-2,-2),colors.red), ('VALIGN',(0,0),(1,-1),'TOP'), ('ALIGN',(0,0),(1,-1),'RIGHT'), ('TEXTCOLOR',(0,0),(1,-1),colors.blue), ('ALIGN',(0,-1),(-1,-1),'CENTER'), ('VALIGN',(0,-1),(-1,-1),'MIDDLE'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.green), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ]) lst.append(t) data = [('alignment', 'align\012alignment'), ('bulletColor', 'bulletcolor\012bcolor'), ('bulletFontName', 'bfont\012bulletfontname'), ('bulletFontSize', 'bfontsize\012bulletfontsize'), ('bulletIndent', 'bindent\012bulletindent'), ('firstLineIndent', 'findent\012firstlineindent'), ('fontName', 'face\012fontname\012font'), ('fontSize', 'size\012fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent\012lindent'), ('rightIndent', 'rightindent\012rindent'), ('spaceAfter', 'spaceafter\012spacea'), ('spaceBefore', 'spacebefore\012spaceb'), ('textColor', 'fg\012textcolor\012color')] t = Table(data) t.setStyle([ ('VALIGN',(0,0),(-1,-1),'TOP'), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ]) lst.append(t) t = Table([ ('Attribute', 'Synonyms'), ('alignment', 'align, alignment'), ('bulletColor', 'bulletcolor, bcolor'), ('bulletFontName', 'bfont, bulletfontname'), ('bulletFontSize', 'bfontsize, bulletfontsize'), ('bulletIndent', 'bindent, bulletindent'), ('firstLineIndent', 'findent, firstlineindent'), ('fontName', 'face, fontname, font'), ('fontSize', 'size, fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent, lindent'), ('rightIndent', 'rightindent, rindent'), ('spaceAfter', 'spaceafter, spacea'), ('spaceBefore', 'spacebefore, spaceb'), ('textColor', 'fg, textcolor, color')]) t.repeatRows = 1 t.setStyle([ ('FONT',(0,0),(-1,1),'Times-Bold',10,12), ('FONT',(0,1),(-1,-1),'Courier',8,8), ('VALIGN',(0,0),(-1,-1),'MIDDLE'), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ('BACKGROUND', (0, 0), (-1, 0), colors.green), ('BACKGROUND', (0, 1), (-1, -1), colors.pink), ('ALIGN', (0, 0), (-1, 0), 'CENTER'), ('ALIGN', (0, 1), (0, -1), 'LEFT'), ('ALIGN', (-1, 1), (-1, -1), 'RIGHT'), ('FONT', (0, 0), (-1, 0), 'Times-Bold', 12), ('ALIGN', (1, 1), (1, -1), 'CENTER'), ]) lst.append(t) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 5,6), ('GRID', (0,0), (-1,-1), 0.25, colors.blue),])) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 10,12), ('GRID', (0,0), (-1,-1), 0.25, colors.black),])) lst.append(Table(XY, style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 20,24), ('GRID', (0,0), (-1,-1), 0.25, colors.red),])) lst.append(PageBreak()) data= [['00', '01', '02', '03', '04'], ['10', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34']] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('BACKGROUND', (1, 1), (1, 2), colors.lavender), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ]) lst.append(Paragraph("Illustrating splits: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) lst.append(PageBreak()) data= [['00', '01', '02', '03', '04'], ['', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '', '33', '34']] sty=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('SPAN',(2,2),(2,3)), ] t=Table(data,style=sty) lst.append(Paragraph("Illustrating splits with spans: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) data= [['00', '01', '02', '03', '04'], ['', '11', '12', '13', ''], ['20', '21', '22', '23', '24'], ['30', '31', '', '33', ''], ['40', '41', '', '43', '44']] sty=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('BOX',(0,0),(-1,-1),2,colors.black), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND',(-2,1),(-1,1),colors.palegreen), ('SPAN',(-2,1),(-1,1)), ('BACKGROUND',(-2,3),(-1,3),colors.yellow), ('SPAN',(-2,3),(-1,3)), ('BACKGROUND', (2, 3), (2, 4), colors.orange), ('SPAN',(2,3),(2,4)), ] t=Table(data,style=sty,repeatRows=2) lst.append(Paragraph("Illustrating splits with spans and repeatRows: nosplit", styleSheet['BodyText'])) lst.append(t) lst.append(Spacer(0,6)) if 1: lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,30)", styleSheet['BodyText'])) for s in t.split(4*inch,30): lst.append(s) lst.append(Spacer(0,6)) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,36)", styleSheet['BodyText'])) for s in t.split(4*inch,36): lst.append(s) lst.append(Spacer(0,6)) lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,56)", styleSheet['BodyText'])) lst.append(Spacer(0,6)) for s in t.split(4*inch,56): lst.append(s) lst.append(Spacer(0,6)) lst.append(PageBreak()) from reportlab.lib.testutils import testsFolder I = Image(os.path.join(os.path.dirname(testsFolder),'src','tools','pythonpoint','demos','leftlogo.gif')) I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth I.drawWidth = 1.25*inch #I.drawWidth = 9.25*inch #uncomment to see better messaging P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"]) B = TableBarChart() BP = Paragraph("<para align=center spaceb=3>A bar chart in a cell.</para>", styleSheet["BodyText"]) data= [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'], ['00', '01', '02', [I,P], '04'], ['10', '11', '12', [I,P], '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34'], ['40', '41', '42', [B,BP], '44']] t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green), ('BOX',(0,0),(1,-1),2,colors.red), ('LINEABOVE',(1,2),(-2,2),1,colors.blue), ('LINEBEFORE',(2,1),(2,-2),1,colors.pink), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('BACKGROUND', (1, 1), (1, 2), colors.lavender), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('BOX',(0,0),(-1,-1),2,colors.black), ('GRID',(0,0),(-1,-1),0.5,colors.black), ('VALIGN',(3,0),(3,0),'BOTTOM'), ('BACKGROUND',(3,0),(3,0),colors.limegreen), ('BACKGROUND',(3,1),(3,1),colors.khaki), ('ALIGN',(3,1),(3,1),'CENTER'), ('BACKGROUND',(3,2),(3,2),colors.beige), ('ALIGN',(3,2),(3,2),'LEFT'), ]) t._argW[3]=1.5*inch lst.append(t) # now for an attempt at column spanning. lst.append(PageBreak()) data= [['A', 'BBBBB', 'C', 'D', 'E'], ['00', '01', '02', '03', '04'], ['10', '11', '12', '13', '14'], ['20', '21', '22', '23', '24'], ['30', '31', '32', '33', '34']] sty = [ ('ALIGN',(0,0),(-1,-1),'CENTER'), ('VALIGN',(0,0),(-1,-1),'TOP'), ('GRID',(0,0),(-1,-1),1,colors.green), ('BOX',(0,0),(-1,-1),2,colors.red), #span 'BBBB' across middle 3 cells in top row ('SPAN',(1,0),(3,0)), #now color the first cell in this range only, #i.e. the one we want to have spanned. Hopefuly #the range of 3 will come out khaki. ('BACKGROUND',(1,0),(1,0),colors.khaki), ('SPAN',(0,2),(-1,2)), #span 'AAA'down entire left column ('SPAN',(0,0), (0, 1)), ('BACKGROUND',(0,0),(0,0),colors.cyan), ('LINEBELOW', (0,'splitlast'), (-1,'splitlast'), 1, colors.white,'butt'), ] t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5) lst.append(t) # now for an attempt at percentage widths lst.append(Spacer(18,18)) lst.append(Paragraph("This table has colWidths=5*['14%']!", styleSheet['BodyText'])) t=Table(data,style=sty, colWidths = ['14%'] * 5, rowHeights = [20]*5) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph("This table has colWidths=['14%','10%','19%','22%','*']!", styleSheet['BodyText'])) t=Table(data,style=sty, colWidths = ['14%','10%','19%','22%','*'], rowHeights = [20]*5) lst.append(t) # Mike's test example lst.append(Spacer(18,18)) lst.append(Paragraph('Mike\'s Spanning Example', styleSheet['Heading1'])) data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], [Paragraph('World <font color="green">Domination</font>: The First Five Years', styleSheet['BodyText']),''], [Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], ] t=Table(data, style=[('SPAN',(0,0),(1,0)),('SPAN',(0,1),(1,1)),('SPAN',(0,2),(1,2)),], colWidths = [3*cm,8*cm], rowHeights = [None]*3) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph('Mike\'s Non-spanning Example', styleSheet['Heading1'])) data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], [Paragraph('World <font color="magenta">Domination</font>: The First Five Years', styleSheet['BodyText'])], [Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], ] t=Table(data, style=[], colWidths = [11*cm], rowHeights = [None]*3) lst.append(t) lst.append(Spacer(18,18)) lst.append(Paragraph('xpre example', styleSheet['Heading1'])) data= [ [ XPreformatted('Account Details', styleSheet['Heading3']), '', XPreformatted('Client Details', styleSheet['Heading3']), ], #end of row 0 ] t=Table(data, style=[], colWidths = [80,230.0,80], rowHeights = [None]*1) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph('Trying colour cycling in background', styleSheet['Heading1'])) lst.append(Paragraph("This should alternate pale blue and uncolored by row", styleSheet['BodyText'])) data= [['001', '01', '02', '03', '04', '05'], ['002', '01', '02', '03', '04', '05'], ['003', '01', '02', '03', '04', '05'], ['004', '01', '02', '03', '04', '05'], ['005', '01', '02', '03', '04', '05'], ['006', '01', '02', '03', '04', '05'], ['007', '01', '02', '03', '04', '05'], ['008', '01', '02', '03', '04', '05'], ['009', '01', '02', '03', '04', '05'], ['010', '01', '02', '03', '04', '05'], ] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('ROWBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, None)), ]) lst.append(t) lst.append(Spacer(0,6)) lst.append(Paragraph("And this should pale blue, pale pink and None by column", styleSheet['BodyText'])) data= [['001', '01', '02', '03', '04', '05'], ['002', '01', '02', '03', '04', '05'], ['003', '01', '02', '03', '04', '05'], ['004', '01', '02', '03', '04', '05'], ['005', '01', '02', '03', '04', '05'], ['006', '01', '02', '03', '04', '05'], ['007', '01', '02', '03', '04', '05'], ['008', '01', '02', '03', '04', '05'], ['009', '01', '02', '03', '04', '05'], ['010', '01', '02', '03', '04', '05'], ] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('COLBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, 0xFFD0D0, None)), ]) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph("This spanning example illustrates automatic removal of grids and lines in spanned cells!", styleSheet['BodyText'])) lst.append(Spacer(0,6)) data= [['Top\nLeft', '', '02', '03', '04', '05', '06', '07'], ['', '', '12', 'Span (3,1) (6,2)', '','','','17'], ['20', '21', '22', '', '','','','27'], ['30', '31', '32', '33', '34','35','36','37'], ['40', 'In The\nMiddle', '', '', '44','45','46','47'], ['50', '', '', '', '54','55','56','57'], ['60', '', '', '','64', '65', 'Bottom\nRight', ''], ['70', '71', '72', '73','74', '75', '', '']] t=Table(data,style=[ ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('BACKGROUND',(0,0),(1,1),colors.palegreen), ('SPAN',(0,0),(1,1)), ('BACKGROUND',(-2,-2),(-1,-1), colors.pink), ('SPAN',(-2,-2),(-1,-1)), ('SPAN',(1,4),(3,6)), ('BACKGROUND',(1,4),(3,6), colors.lightblue), ('SPAN',(3,1),(6,2)), ('BACKGROUND',(3,1),(6,2), colors.peachpuff), ('VALIGN',(3,1),(6,2),'TOP'), ('LINEABOVE', (0,2),(-1,2), 1, colors.black, 0, None, None, 2, 2), ('LINEBEFORE', (3,0),(3,-1), 1, colors.black, 0, None, None, 2, 2), ]) lst.append(t) lst.append(PageBreak()) lst.append(Paragraph("und jetzt noch eine Tabelle mit 5000 Zeilen:", styleSheet['BodyText'])) sty = [ ('GRID',(0,0),(-1,-1),1,colors.green), ('BOX',(0,0),(-1,-1),2,colors.red), ] data = [[str(i), Paragraph("xx "* (i%10), styleSheet["BodyText"]), Paragraph("blah "*(i%40), styleSheet["BodyText"])] for i in range(500)] t=LongTable(data, style=sty, colWidths = [50,100,200]) lst.append(t) #Yuan Hong's bug tester lst.append(PageBreak()) lst.append(Paragraph('Yian Hong\'s Bug Case (should not blow up)', styleSheet['Heading2'])) data = ([['Col1', 'Col2', 'Col3', 'Col4', 'Col5']]+ [['01', Paragraph('This is cell one that contains a paragraph.', styleSheet['Normal']), '02', '03', '04'] for i in range(50)]) t = Table(data, ['20%']*5, repeatRows=1) t.setStyle(TableStyle([ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ('SPAN', (0,50), (-2,50)), ])) lst.append(t) lst.append(PageBreak()) #Volker Haas' example extended #the optimal row heights are the solution of an LP similar to # #Objective function # min: 3*h0+3*h1+3*h2+2*h3; # #constraints # h0>=12; # h1>=12; # h2>=12; # h3>=12; # h0+h1+h2>=48; # h0+h1>=12; # h2+h3>=60; # #the solution H=[12,12,24,36] def makeTable(x,y): return Table([ ['00', '01', '02', '03', '04', '05\nline2\nline3\nline4'], ['', '11', '12', x, '',''], ['20', '21', y, '23', '24',''], ['30', '31', '', '33', '34','35'], ], style=[ ('TOPPADDING',(0,0),(-1,-1),0), ('BOTTOMPADDING',(0,0),(-1,-1),0), ('RIGHTPADDING',(0,0),(-1,-1),0), ('LEFTPADDING',(0,0),(-1,-1),0), ('GRID',(0,0),(-1,-1),0.5,colors.grey), ('BACKGROUND', (0, 0), (0, 1), colors.pink), ('SPAN',(0,0),(0,1)), ('BACKGROUND', (2, 2), (2, 3), colors.orange), ('SPAN',(2,2),(2,3)), ('SPAN',(3,1),(4,1)), ('SPAN',(5,0),(5,2)), ]) p_style= ParagraphStyle('Normal') lst.append(makeTable( Paragraph('This is a string',p_style), Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) lst.append(Spacer(10,10)) lst.append(makeTable( XPreformatted('This is a string',p_style), Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) lst.append(Spacer(10,10)) lst.append(makeTable( 'This is a string', '22\nblub\nasfd\nafd\nasdfs', )) lst.append(Spacer(10,10)) lst.append(makeTable( 'This is a string', Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) )) SimpleDocTemplate(outputfile('test_platypus_tables_2.pdf'), showBoundary=1).build(lst)
def insertImage(self, imagePath, height, width): img = Image(imagePath) img.drawHeight = height img.drawWidth = width self.Story.append(img)
_style = ParagraphStyle('Courier',fontName="Courier", fontSize=10, leading = 15) _styleD1 = ParagraphStyle('Courier',fontName="Courier", fontSize=9, leading = 15) _stylePR = ParagraphStyle('Courier',fontName="Courier", fontSize=8) _table_heading = ParagraphStyle('Courier',fontName="Courier", fontSize=7, leading = 10) styles.add(ParagraphStyle(name='Wrap', fontSize=8, wordWrap='LTR', firstLineIndent = 0,alignment = TA_LEFT)) row = [] ctr = 0 tmpfilename=os.path.join(request.folder,'private',str(uuid4())) # doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=200,bottomMargin=200, showBoundary=1) # doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=2.1 * inch, bottomMargin=1.5 * inch)#, showBoundary=1) doc = SimpleDocTemplate(tmpfilename,pagesize=A4, rightMargin=20,leftMargin=20, topMargin=2.7 * inch,bottomMargin=2.4 * inch)#, showBoundary=1) _merchandpartners = request.folder + '/static/images/merchpartners.jpg' _img = Image(_merchandpartners) _img.drawHeight = 2.55 *inch * _img.drawHeight / _img.drawWidth _img.drawWidth = 3.25 * inch _img.hAlign = 'CENTER' _MerchAndPartners = Image(_merchandpartners, width = 550, height = 80, hAlign = 'CENTER') _merchtrading = request.folder + '/static/images/merchtrading.jpg' _img = Image(_merchtrading) _img.drawHeight = 2.55 *inch * _img.drawHeight / _img.drawWidth _img.drawWidth = 3.25 * inch _img.hAlign = 'CENTER' _MerchTrading = Image(_merchtrading, width = 550, height = 80, hAlign = 'CENTER') def get_account_voucher_canvas(canvas, doc): canvas.saveState() _id = db(db.Payment_Voucher_Header.payment_voucher_no == request.args(0)).select().first()
firstLineIndent=0, alignment=TA_LEFT)) row = [] ctr = 0 tmpfilename = os.path.join(request.folder, 'private', str(uuid4())) doc = SimpleDocTemplate(tmpfilename, pagesize=A4, rightMargin=30, leftMargin=30, topMargin=1 * inch, bottomMargin=.8 * inch) #,showBoundary=1) logo_path = request.folder + '/static/images/Merch.jpg' _limage = Image(logo_path) _limage.drawHeight = 2.55 * inch * _limage.drawHeight / _limage.drawWidth _limage.drawWidth = 2.25 * inch _limage.hAlign = 'CENTER' def landscape_header(canvas, doc): canvas.saveState() header = Table([[_limage]], colWidths='*') header.setStyle( TableStyle([ # ('GRID',(0,0),(-1,-1),0.5, colors.Color(0, 0, 0, 0.2)), ('FONTSIZE', (0, 0), (-1, -1), 12), ('FONTNAME', (0, 0), (-1, -1), 'Courier'), ('ALIGN', (0, 0), (0, -1), 'CENTER') ])) header.wrapOn(canvas, doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - .3 * cm)
def createpdf(filehandle, content): """Funktion zum Schreiben der PDF-Datei""" story = [] # Alle Elemente des PDFs werden der Story hinzugefuegt # Styles fuer normale Paragraphen, gelesen aus dem SampleStyleSheet stylesheet = getSampleStyleSheet() h1 = stylesheet['Heading1'] h1.fontname = 'DGUVBold' h2 = stylesheet['Heading2'] h2.fontName = 'DGUVBold' h3 = stylesheet['Heading3'] h3.fontname = 'DGUVBold' code = stylesheet['Code'] bodytext = stylesheet['BodyText'] bodytext.fontName = 'DGUVBold' bodybold = stylesheet['BodyText'] bodybold.fontName = 'DGUVBold' # Weitere Styles fuer Paragraphen stylesheet.add( ParagraphStyle(name='smallbody', fontName='DGUVNormal', fontSize=9, spaceAfter=5)) stylesheet.add( ParagraphStyle(name='normal', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='free', fontName='DGUVNormal', fontSize=7.5, borderPadding=0)) stylesheet.add( ParagraphStyle(name='right', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_r)) stylesheet.add( ParagraphStyle(name='center', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_c)) stylesheet.add( ParagraphStyle(name='bold', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='boldnew', fontName='DGUVBold', fontSize=9, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='boldright', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_r)) stylesheet.add( ParagraphStyle(name='boldcenter', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_c)) smallbody = stylesheet['smallbody'] bullet = stylesheet['Bullet'] bullet.fontSize = 9 bullet.fontName = 'DGUVNormal' entry_normal = stylesheet['normal'] entry_free = stylesheet['free'] entry_right = stylesheet['right'] entry_center = stylesheet['center'] entry_bold = stylesheet['bold'] entry_boldnew = stylesheet['boldnew'] entry_boldright = stylesheet['boldright'] entry_boldcenter = stylesheet['boldcenter'] # Add your logo to the page head. #im = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'images/bghw.jpg') #logo = Image(im, 6.22 * cm, 2 * cm) #logo.hAlign = 'RIGHT' #story.append(logo) #story.append(Spacer(0 * cm, 1.5 * cm)) im = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'images/logo_etem.jpg') logo = Image(im) logo.drawHeight = 6 * cm * logo.drawHeight / logo.drawWidth logo.drawWidth = 6 * cm logo.hAlign = 'RIGHT' # Datum datum = u"Datum: %s" % (strftime("%d.%m.%Y")) zeit = u"Zeit: %s" % (strftime("%H:%M:%S", localtime())) colWidths = [9.5 * cm, 2.75 * cm, 6.25 * cm] testcontent = u"Ergänzung der Gefährdungsbeurteilung für Bau- und Montagestellen zum Schutz vor Infektion mit dem Coronavirus" testheadline = u'<font color="#008c8e"><b>%s</b></font>' % testcontent toptable = [[Paragraph(testheadline, h2), Paragraph(u" ", bodytext), logo]] table = Table(toptable, colWidths=colWidths) table.hAlign = 'CENTER' story.append(table) story.append(Spacer(0 * cm, 0.5 * cm)) textbox_name = InteractiveTextField('Name', 250) textbox_datum = InteractiveTextField('Datum', 250) textbox_unternehmer = InteractiveTextField('Unternehmer/Unternehmerin', 250) story.append(Paragraph(u"Firma", entry_free)) story.append(textbox_name) story.append(Spacer(0 * cm, 0.1 * cm)) story.append(Paragraph(u"Datum", entry_free)) story.append(textbox_datum) story.append(Spacer(0 * cm, 0.1 * cm)) story.append(Paragraph(u"Unternehmer/Unternehmerin", entry_free)) story.append(textbox_unternehmer) story.append(Spacer(0 * cm, 0.5 * cm)) #story.append(Paragraph(absatz1, smallbody)) #story.append(Spacer(0 * cm, 0.25* cm)) #story.append(Paragraph(absatz2, smallbody)) #story.append(Spacer(0 * cm, 0.25* cm)) #story.append(Paragraph(absatz3, smallbody)) #story.append(Spacer(0 * cm, 0.25* cm)) #story.append(Paragraph(absatz4, smallbody)) #story.append(Spacer(0 * cm, 0.25* cm)) #for i in bulletlist: # listentry = "<bullet>•</bullet>%s" %i # story.append(Paragraph(listentry, bullet)) #story.append(Spacer(0 * cm, 0.25* cm)) #story.append(Paragraph(absatz5, smallbody)) ctt = [] ctt.append(Paragraph(absatz1, smallbody)) ctt.append(Paragraph(absatz2, smallbody)) ctt.append(Paragraph(absatz3, smallbody)) ctt.append(Paragraph(absatz4, smallbody)) for i in bulletlist: listentry = "<bullet>•</bullet>%s" % i ctt.append(Paragraph(listentry, bullet)) ctt.append(Paragraph(absatz5, smallbody)) story.append( BalancedColumns(ctt, nCols=2, needed=72, spaceBefore=0, spaceAfter=0)) story.append(Spacer(0 * cm, 1 * cm)) # optional: Festlegung fester Tabellenbreiten colWidths = [8 * cm, 1.25 * cm, 1.25 * cm, 8 * cm] checkbox_1 = InteractiveCheckBox('cb1') checkbox_2 = InteractiveCheckBox('cb2') textbox_1 = InteractiveTextField('zeile1') textbox_2 = InteractiveTextField('zeile2') checkbox_3 = InteractiveCheckBox('cb3') checkbox_4 = InteractiveCheckBox('cb4') textbox_3 = InteractiveTextField('zeile4') textbox_4 = InteractiveTextField('zeile5') mytable = [] tableheader = [ Paragraph(u"Organisation", entry_bold), Paragraph(u"ja", entry_boldcenter), Paragraph(u"nein", entry_boldcenter), Paragraph(u"Bemerkung/Maßnahme", entry_bold) ] mytable.append(tableheader) tablebody = [ Paragraph(zelle1, entry_normal), checkbox_1, checkbox_2, [textbox_1, textbox_2], ] mytable.append(tablebody) tablebody = [ Paragraph(zelle2, entry_normal), checkbox_3, checkbox_4, [textbox_3, textbox_4], ] mytable.append(tablebody) table = Table(mytable, repeatRows=1, colWidths=colWidths, style=[('GRID', (0, 0), (-1, -1), 1, grey), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')]) table.hAlign = "LEFT" story.append(table) story.append(PageBreak()) story.append(Spacer(0 * cm, 1 * cm)) story.append( Paragraph(u"Weitere Maßnahmen (z. B. Notfall- oder Pandemieplan):", smallbody)) story.append(Spacer(0 * cm, 0.5 * cm)) story.append(InteractiveTextField('massnahme1', 500)) story.append(InteractiveTextField('massnahme2', 500)) story.append(InteractiveTextField('massnahme3', 500)) story.append(InteractiveTextField('massnahme4', 500)) story.append(InteractiveTextField('massnahme5', 500)) story.append(InteractiveTextField('massnahme6', 500)) story.append(InteractiveTextField('massnahme7', 500)) story.append(InteractiveTextField('massnahme8', 500)) story.append(Spacer(0 * cm, 14 * cm)) schlusstext = u"""Diese Gefährdungsbeurteilung ergänzt die betriebliche Gefährdungsbeurteilung. Sie wurde vor Beginn der Arbeiten erstellt, die Maßnahmen wurden umgesetzt und auf Wirksamkeit überprüft. Die Mitarbeiter sind unterwiesen.""" schlussline = u'<font color="#008c8e"><b>%s</b></font>' % schlusstext story.append(Paragraph(schlussline, bodybold)) story.append(Spacer(0 * cm, 0.5 * cm)) textbox_name = InteractiveTextField('name_verantwortlich', 250) textbox_unterschrift = InteractiveTextField('datum_unterschrift', 250) colWidths = [9.25 * cm, 9.25 * cm] signtable = [[textbox_name, textbox_unterschrift], [ Paragraph(u"Name des Arbeitsverantwortlichen", entry_free), Paragraph(u"Datum, Unterschrift", entry_free) ]] table = Table(signtable, colWidths=colWidths) table.hAlign = 'CENTER' story.append(table) story.append(Spacer(0 * cm, 1 * cm)) colWidths = [8 * cm, 4.5 * cm, 6 * cm] datatable = [[ Paragraph(u" "), Paragraph(u"25.05.2020, Version 3", entry_free), Paragraph(u"Bestell-Nr. GB-C01", entry_boldright) ]] table = Table(datatable, colWidths=colWidths) story.append(table) doc = PdfBaseTemplate(filehandle, pagesize=A4) doc.build(story, canvasmaker=NumberedCanvas)
def createpdf(filehandle, content): """Funktion zum Schreiben der PDF-Datei""" story = [] # Alle Elemente des PDFs werden der Story hinzugefuegt # Styles fuer normale Paragraphen, gelesen aus dem SampleStyleSheet stylesheet = getSampleStyleSheet() h1 = stylesheet['Heading1'] h1.fontname = 'DGUVBold' h2 = stylesheet['Heading2'] h2.fontName = 'DGUVBold' h3 = stylesheet['Heading3'] h3.fontname = 'DGUVBold' code = stylesheet['Code'] bodytext = stylesheet['BodyText'] bodytext.fontName = 'DGUVNormal' bodybold = stylesheet['BodyText'] bodybold.fontName = 'DGUVBold' # Weitere Styles fuer Paragraphen stylesheet.add( ParagraphStyle(name='smallbody', fontName='DGUVNormal', fontSize=9, spaceAfter=5)) stylesheet.add( ParagraphStyle(name='normal', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='free', fontName='DGUVNormal', fontSize=7.5, borderPadding=0)) stylesheet.add( ParagraphStyle(name='right', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_r)) stylesheet.add( ParagraphStyle(name='center', fontName='DGUVNormal', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_c)) stylesheet.add( ParagraphStyle(name='bold', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='boldnew', fontName='DGUVBold', fontSize=9, borderPadding=(5, 3, 3, 5))) stylesheet.add( ParagraphStyle(name='boldright', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_r)) stylesheet.add( ParagraphStyle(name='boldcenter', fontName='DGUVBold', fontSize=7.5, borderPadding=(5, 3, 3, 5), alignment=_c)) smallbody = stylesheet['smallbody'] bullet = stylesheet['Bullet'] bullet.fontSize = 9 bullet.fontName = 'DGUVNormal' entry_normal = stylesheet['normal'] entry_free = stylesheet['free'] entry_right = stylesheet['right'] entry_center = stylesheet['center'] entry_bold = stylesheet['bold'] entry_boldnew = stylesheet['boldnew'] entry_boldright = stylesheet['boldright'] entry_boldcenter = stylesheet['boldcenter'] coronastyles = {} coronastyles['h1'] = h1 coronastyles['h2'] = h2 coronastyles['h3'] = h3 coronastyles['code'] = code coronastyles['bodytext'] = bodytext coronastyles['bodybold'] = bodybold coronastyles['smallbody'] = smallbody coronastyles['bullet'] = bullet coronastyles['entry_normal'] = entry_normal coronastyles['entry_free'] = entry_free coronastyles['entry_right'] = entry_right coronastyles['entry_center'] = entry_center coronastyles['entry_bold'] = entry_bold coronastyles['entry_boldnew'] = entry_boldnew coronastyles['entry_boldright'] = entry_boldright coronastyles['entry_boldcenter'] = entry_boldcenter im = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'images/logo_etem.jpg') logo = Image(im) logo.drawHeight = 6 * cm * logo.drawHeight / logo.drawWidth logo.drawWidth = 6 * cm logo.hAlign = 'RIGHT' # Datum datum = u"Datum: %s" % (strftime("%d.%m.%Y")) zeit = u"Zeit: %s" % (strftime("%H:%M:%S", localtime())) colWidths = [9.5 * cm, 2.75 * cm, 6.25 * cm] formtitle = content.get('title') testheadline = u'<font color="#008c8e"><b>%s</b></font>' % formtitle toptable = [[Paragraph(testheadline, h2), Paragraph(u" ", bodytext), logo]] table = Table(toptable, colWidths=colWidths, style=[('VALIGN', (0, 0), (-1, -1), 'TOP')]) table.hAlign = 'CENTER' story.append(table) story.append(Spacer(0 * cm, 0.5 * cm)) textbox_name = InteractiveTextField('Name', 250) textbox_datum = InteractiveTextField('Datum', 250) textbox_unternehmer = InteractiveTextField('Unternehmer/Unternehmerin', 250) story.append(Paragraph(u"Firma", entry_free)) story.append(textbox_name) story.append(Spacer(0 * cm, 0.1 * cm)) story.append(Paragraph(u"Datum", entry_free)) story.append(textbox_datum) story.append(Spacer(0 * cm, 0.1 * cm)) story.append(Paragraph(u"Unternehmer/Unternehmerin", entry_free)) story.append(textbox_unternehmer) story.append(Spacer(0 * cm, 0.5 * cm)) for i in content.get('content'): if i.portal_type == 'Textblock': blockkey = 'textblock_%s' % i.UID() textblock = content.get(blockkey) if i.spalten == 2: story = create_columnblock(textblock, coronastyles, story) else: story = create_textblock(textblock, coronastyles, story) story.append(Spacer(0 * cm, 1 * cm)) elif i.portal_type == 'Tabelle': story.append(create_tabelle(i, coronastyles, 'nva' + i.UID())) story.append(Spacer(0 * cm, 1 * cm)) elif i.portal_type == 'Ueberschrift': story.append(Paragraph(i.title, coronastyles[i.format])) story.append(PageBreak()) story.append(Spacer(0 * cm, 1 * cm)) story.append( Paragraph(u"Weitere Maßnahmen (z. B. Notfall- oder Pandemieplan):", smallbody)) story.append(Spacer(0 * cm, 0.5 * cm)) story.append(InteractiveTextField('massnahme1', 500)) story.append(InteractiveTextField('massnahme2', 500)) story.append(InteractiveTextField('massnahme3', 500)) story.append(InteractiveTextField('massnahme4', 500)) story.append(InteractiveTextField('massnahme5', 500)) story.append(InteractiveTextField('massnahme6', 500)) story.append(InteractiveTextField('massnahme7', 500)) story.append(InteractiveTextField('massnahme8', 500)) story.append(Spacer(0 * cm, 14 * cm)) schlusstext = u"""Diese Gefährdungsbeurteilung ergänzt die betriebliche Gefährdungsbeurteilung. Sie wurde vor Beginn der Arbeiten erstellt, die Maßnahmen wurden umgesetzt und auf Wirksamkeit überprüft. Die Mitarbeiter sind unterwiesen.""" schlussline = u'<font color="#008c8e"><b>%s</b></font>' % schlusstext story.append(Paragraph(schlussline, bodybold)) story.append(Spacer(0 * cm, 0.5 * cm)) textbox_name = InteractiveTextField('name_verantwortlich', 250) textbox_unterschrift = InteractiveTextField('datum_unterschrift', 250) colWidths = [9.25 * cm, 9.25 * cm] signtable = [[textbox_name, textbox_unterschrift], [ Paragraph(u"Name des Arbeitsverantwortlichen", entry_free), Paragraph(u"Datum, Unterschrift", entry_free) ]] table = Table(signtable, colWidths=colWidths) table.hAlign = 'CENTER' story.append(table) story.append(Spacer(0 * cm, 1 * cm)) colWidths = [8 * cm, 4.5 * cm, 6 * cm] datum_version = "%s, Version %s" % (content.get('stand'), content.get('version')) bestellnummer = "Bestell-Nr. %s" % content.get('bestellnr') datatable = [[ Paragraph(u" "), Paragraph(datum_version, entry_free), Paragraph(bestellnummer, entry_boldright) ]] table = Table(datatable, colWidths=colWidths) story.append(table) doc = PdfBaseTemplate(filehandle, pagesize=A4) doc.build(story, canvasmaker=NumberedCanvas)
#from reportlab.pdfbase import pdfdoc #pdfdoc.PDFCatalog.OpenAction = '<</S/JavaScript/JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)>>' styles = getSampleStyleSheet() styleN = styles['Normal'] styleH = styles['Heading1'] tmpfilename=os.path.join(request.folder,'private',str(uuid4())) doc = SimpleDocTemplate(tmpfilename,pagesize=A4, topMargin=1.8*inch, leftMargin=30, rightMargin=30)#, showBoundary=1) logo_path = request.folder + 'static/images/kds-logo.jpg' row = [] I = Image(logo_path) I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth I.drawWidth = 1.25*inch I.hAlign='RIGHT' darwish = Paragraph('''<font size=14><b>Darwish Group </b><font color="gray">|</font></font> <font size=9 color="gray"> Fleet Management System</font>''',styles["BodyText"]) ########### def _title(title): title = 'Title' return str(title) def _header_footer(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() # Header 'Vehicle Summary Report'