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

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

VB.NET Discussion :

vb.net et Itextsahrp


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2011
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Août 2011
    Messages : 27
    Par défaut vb.net et Itextsahrp
    Bonjour à la communauté,

    Je développe une application à l’aide de Visual Sutio 2017 en vb.net. J’utilise Itextsharp (V5) afin de générer des Pdf au format paysage a partir de datagridview.
    Ci-dessous ma sub :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
     
        Public Sub SendToPDF(dgv As DataGridView, folderPath As String, titre As String, col_h_debut As Integer, col_b_debut As Integer, col_h_fin As Integer, col_b_fin As Integer)
            Try
                ' Format de la page PDF à générer
                Dim doc As Document = New Document(PageSize.A4.Rotate, 30.0F, 30.0F, 20.0F, 20.0F)
                ' Emplacement du fichier à créer
                ' Nom et droits d'accès du PDF créé
                PdfWriter.GetInstance(doc, New FileStream(folderPath & titre & ".pdf", FileMode.Create))
                ' Police pour le titre
                Dim titleFont As Font = New Font(iTextSharp.text.Font.TIMES_ROMAN, 28.0F, iTextSharp.text.Font.BOLD, Color.BLACK)
                ' Police pour le tableau
                Dim tableFont As Font = New Font(iTextSharp.text.Font.TIMES_ROMAN, 7.0F, iTextSharp.text.Font.NORMAL, Color.BLACK)
                ' Police pour les entetes de colonnes
                Dim headerFont As Font = New Font(iTextSharp.text.Font.TIMES_ROMAN, 7.0F, iTextSharp.text.Font.BOLD, Color.BLACK)
                ' Définition du tableau
                Dim table As PdfPTable = New PdfPTable((col_h_fin - col_h_debut) + 1)
                table.HorizontalAlignment = 1  ' 0 - gauche, 1 - centré, 2 - droite
                table.SpacingBefore = 1.0F
                table.WidthPercentage = 100
     
                doc.Open()
     
                'Ajou d'un logo
                Dim logo = Path.Combine(My.Application.Info.DirectoryPath.ToString() & "\logo.png")
     
                doc.Add(iTextSharp.text.Image.GetInstance(logo))
     
                'Ajout d'un titre
                Dim titre2 As String
                titre2 = Chr(10) & titre & Chr(10)
     
                Dim title As Phrase = New Phrase(New Chunk(titre2, titleFont))
                doc.Add(title)
     
                'Entêtes de colonnes
                For i As Integer = col_h_debut To col_h_fin
                    Dim cell As New PdfPCell(New Phrase(New Chunk(dgv.Columns(i).HeaderText, headerFont)))
                    cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER
                    cell.VerticalAlignment = PdfPCell.ALIGN_CENTER
                    cell.BackgroundColor = New iTextSharp.text.Color(204, 229, 255)
                    table.AddCell(cell)
                Next
     
                ' Ajout des rows
                For i As Integer = 0 To dgv.Rows.Count - 1
                    For j As Integer = col_b_debut To col_b_fin
                        Dim cellule As New PdfPCell(New Phrase(dgv(j, i).Value.ToString(), tableFont))
                        'aligmenet des cellules en fonction du contenu
                        cellule.VerticalAlignment = Element.ALIGN_MIDDLE
                        Select Case dgv.Columns(j).ValueType.ToString
                            Case ("System.Double")
                                cellule.HorizontalAlignment = Element.ALIGN_RIGHT
                            Case ("System.Int32")
                                cellule.HorizontalAlignment = Element.ALIGN_CENTER
                            Case ("System.Int64")
                                cellule.HorizontalAlignment = Element.ALIGN_CENTER
                            Case ("System.Int16")
                                cellule.HorizontalAlignment = Element.ALIGN_CENTER
                            Case ("System.Integer")
                                cellule.HorizontalAlignment = Element.ALIGN_CENTER
                            Case ("System.DateTime")
                                cellule = New PdfPCell(New Phrase(Mid(dgv(j, i).Value.ToString(), 1, 10), tableFont))
                                cellule.HorizontalAlignment = Element.ALIGN_CENTER
                                cellule.VerticalAlignment = Element.ALIGN_MIDDLE
                            Case ("System.String")
                                cellule.HorizontalAlignment = Element.ALIGN_LEFT
                            Case Else
                                cellule.HorizontalAlignment = Element.ALIGN_RIGHT
                        End Select
                        table.AddCell(cellule)
                    Next
                Next
     
                doc.Add(table)
                doc.Close()
     
                MessageBox.Show("Exportation des informations effectuée avec succès !" & Chr(10) & Chr(10) & "Fichier : " & titre & Chr(10) & Chr(10) & " Emplacement : " & folderPath, "Information système", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                If MsgBox("Souhaitez vous visualiser le document généré ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, "Demande de confirmation...") = MsgBoxResult.Yes Then
                    Dim monprocess As New Process()
                    Dim taille_fichier As System.IO.FileInfo
                    taille_fichier = My.Computer.FileSystem.GetFileInfo("C:\Users\" & Environment.UserName & "\Desktop\" & titre & ".pdf")
                    If taille_fichier.Length > 0 Then
                        monprocess.StartInfo.FileName = ("C:\Users\" & Environment.UserName & "\Desktop\" & titre & ".pdf")
                        monprocess.Start()
                        'monprocess.WaitForExit()
                    Else
                        MsgBox("Problème de lecture du fichier Pdf", MsgBoxStyle.Critical, "Erreur système")
                        Exit Sub
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
    Je souhaiterai pour chaque fichiers générés insérer en pied de page un numérotation.
    A défaut : page 1,2,etc. Au mieux page 1/X, 2/X,etc

    Après quelques heures de recherche, et sauf erreur de ma part, il semblerait que Itextsharp ne gère pas à la «*volée*» la numérotation de page et qu’il soit nécessaire de générer celle-ci sur un fichier Pdf déjà existant.

    Auriez-vous une orientation à me recommander, en vous remerciant par avance.

    Thierry

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2011
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Août 2011
    Messages : 27
    Par défaut Myself
    Solution trouvée en Standalone

    Thierry

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débat] Technologie .NET vs JAVA
    Par neo.51 dans le forum Débats sur le développement - Le Best Of
    Réponses: 1047
    Dernier message: 14/01/2019, 16h15
  2. [Débat] Expériences au sujet de .NET
    Par DevX dans le forum Débats sur le développement - Le Best Of
    Réponses: 46
    Dernier message: 25/05/2014, 11h16
  3. A ceux qui ont migré de VB6 vers VB.Net
    Par Fox dans le forum VB 6 et antérieur
    Réponses: 81
    Dernier message: 21/05/2008, 14h56
  4. utiliser les tag [MFC] [Win32] [.NET] [C++/CLI]
    Par hiko-seijuro dans le forum Visual C++
    Réponses: 8
    Dernier message: 08/06/2005, 15h57
  5. Fichier PDOXUSRS.NET
    Par yannick dans le forum Paradox
    Réponses: 5
    Dernier message: 05/04/2002, 09h45

Partager

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