1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
Private Sub BtValider_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtValider.Click
'Création d'un document
Dim newDoc = New Document
'Allocation d'un nom et du mode de traitement
Dim fs As New FileStream("ficheTracteur.pdf", FileMode.Create)
'On instancie le writer
PdfWriter.GetInstance(newDoc, fs)
'Création du header avec un logo et un titre
'l'image est générée à partir de son adresse système
Dim logo As Image = Image.GetInstance(TextBoxLogo.Text)
'on donne à l'image sa taille
logo.ScaleAbsolute(57, 57)
'définition en % des dimensions de chaque colonne à l'aide d'un tableau de single
Dim tailleCol As Single() = {10%, 90%}
'on attribue les dimension à la PdfPTable
Dim titre As PdfPTable = New PdfPTable(tailleCol)
'on définie les propriétés de la table(ici la couleur de fond et des bordures)
titre.DefaultCell.BorderColor = BaseColor.WHITE
titre.DefaultCell.BackgroundColor = BaseColor.BLACK
'on se sert du tableau de single pour définir cette fois la taille des colonnes en pts
tailleCol(0) = 57
tailleCol(1) = 483
'on dit à la table la largeur qu'ele doit faire sans oublier de la locker
titre.SetTotalWidth(tailleCol)
titre.LockedWidth = True
'on ajoute les cellules à la table
'une cellule avec photo
titre.AddCell(logo)
'une cellule avec du texte(police, taille, style, couleur)
titre.AddCell(New Phrase(TbTitre.Text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.Bold, BaseColor.WHITE)))
'on stipule l'espace avant le prochain élément
titre.SpacingAfter = 14
'et on recommence ;)
Dim photo1 As Image = Image.GetInstance(TbPhoto1.Text)
photo1.ScaleAbsolute(540, 325)
'ici une seule case et une seule colonne
Dim taillephoto1 As Single() = {100%}
Dim photo As PdfPTable = New PdfPTable(taillephoto1)
photo.DefaultCell.BorderColor = BaseColor.WHITE
taillephoto1(0) = 540
photo.SetTotalWidth(taillephoto1)
photo.LockedWidth = True
Dim myCell As PdfPCell = New PdfPCell(photo1)
'fixation de la hauteur sinon l'image sera carré par défaut...
myCell.FixedHeight = 325
myCell.HasFixedHeight()
photo.AddCell(myCell)
'c'est encore reparti pour un tour...
Dim photo2 As Image = Image.GetInstance(TbPhoto2.Text)
photo2.ScaleAbsolute(298, 227)
Dim photo3 As Image = Image.GetInstance(TbPhoto3.Text)
photo3.ScaleAbsolute(227, 227)
'une case à 3% pour l'espace entre les deux photos
Dim taillePhoto As Single() = {55%, 3%, 42%}
Dim photo2et3 As PdfPTable = New PdfPTable(taillePhoto)
photo2et3.DefaultCell.BorderColor = BaseColor.WHITE
taillePhoto(0) = 298
taillePhoto(1) = 15
taillePhoto(2) = 227
photo2et3.SetTotalWidth(taillePhoto)
photo2et3.LockedWidth = True
photo2et3.AddCell(photo2)
photo2et3.AddCell(New Phrase(""))
photo2et3.AddCell(photo3)
photo2et3.SpacingBefore = 14
photo2et3.SpacingAfter = 14
'nouvelle table
Dim tailleColPart As Single() = {100%}
Dim listeParticularitePDF As PdfPTable = New PdfPTable(tailleColPart)
tailleColPart(0) = 540
listeParticularitePDF.SetTotalWidth(tailleColPart)
listeParticularitePDF.LockedWidth = True
Dim monTitre As Phrase = New Phrase(partTrad, FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.Bold, BaseColor.WHITE))
Dim cellTitre As PdfPCell = New PdfPCell(monTitre)
cellTitre.BackgroundColor = BaseColor.BLACK
listeParticularitePDF.AddCell(cellTitre)
For Each p As Particularites In listeParticularites
Dim part As Phrase = New Phrase(p.Part_ID.ToString + ". " + p.Part_LIB.ToLower + ".", FontFactory.GetFont(FontFactory.HELVETICA, 10))
Dim cellPart As PdfPCell = New PdfPCell(part)
cellPart.BorderColor = BaseColor.WHITE
listeParticularitePDF.AddCell(cellPart)
Next
'définition du footer
Dim tailleSignature As Single() = {40%, 30%, 30%}
Dim signature As PdfPTable = New PdfPTable(tailleSignature)
tailleSignature(0) = 216
tailleSignature(1) = 162
tailleSignature(2) = 162
signature.SetTotalWidth(tailleSignature)
signature.LockedWidth = True
signature.DefaultCell.BorderColor = BaseColor.WHITE
Dim mesCoord As Phrase = New Phrase("blabla (adresse, email, tel, fax)", FontFactory.GetFont(FontFactory.HELVETICA, 6))
Dim maCell As PdfPCell = New PdfPCell(mesCoord)
maCell.HorizontalAlignment = Element.ALIGN_RIGHT
maCell.BorderColor = BaseColor.WHITE
Dim sign As Image = Image.GetInstance("chemin logo entreprise")
sign.ScaleAbsoluteHeight(85)
signature.AddCell("")
signature.AddCell(maCell)
signature.AddCell(sign)
'on ouvre le document, on ajoute toute les tables, puis on le referme
newDoc.Open()
newDoc.Add(titre)
newDoc.Add(photo)
newDoc.Add(photo2et3)
newDoc.Add(listeParticularitePDF)
newDoc.Add(signature)
newDoc.Close()
fs.Close()
End Sub |