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

Dotnet Discussion :

Générateur Pdf en C#


Sujet :

Dotnet

  1. #1
    Membre du Club
    Homme Profil pro
    Consultant Marketing
    Inscrit en
    Mars 2016
    Messages
    285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant Marketing
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2016
    Messages : 285
    Points : 57
    Points
    57
    Par défaut Générateur Pdf en C#
    Bonjour,

    J'ai un petit programme pour générer des Pdf en C# qui fonctionne très bien, le soucis c'est que il fonctionne que pour un produit donc je pense qu'il faudrait faire une boucle sur l'ensemble des produits ?
    J'utile Visual Studio Community.

    Pouvez vous m'aider ?

    Merci à vous

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
     
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
     
    namespace WindowsFormsAppDevis
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
     
            }
     
            private void label1_Click(object sender, EventArgs e)
            {
     
            }
     
            private void label3_Click(object sender, EventArgs e)
            {
     
            }
     
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void label5_Click(object sender, EventArgs e)
            {
     
            }
     
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                generatePdf();
            }
     
            public void generatePdf()
            {
                string outfile = Environment.CurrentDirectory + "/devis.pdf";
                // Création du document
                Document doc = new Document();
                PdfWriter.GetInstance(doc, new FileStream(outfile, FileMode.Create));
                doc.Open();
     
                // Palette de couleurs
                BaseColor blue = new BaseColor(0, 75, 155);
                BaseColor gris = new BaseColor(240, 240, 240);
                BaseColor blanc = new BaseColor(255, 255, 255);
     
                // Polices d'écriture
                Font policeTitre = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20f, iTextSharp.text.Font.BOLD, blue);
                Font policeTh = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16f, 1, blanc);
     
                // Page Pdf
                // Création de paragraphes
                Paragraph p1 = new Paragraph("devis-test, " + mesInfos.Text + "\n\n", policeTitre);
                p1.Alignment = Element.ALIGN_LEFT;
                doc.Add(p1);
     
                Paragraph p2 = new Paragraph("Le client, " + client.Text + "\n\n", policeTitre);
                p2.Alignment = Element.ALIGN_RIGHT;
                doc.Add(p2);
     
                Paragraph p3 = new Paragraph("Devis : " + titre.Text + "\n\n", policeTitre);
                p3.Alignment = Element.ALIGN_LEFT;
                doc.Add(p3);
     
     
                // Création du tableau des produits
                PdfPTable tableau = new PdfPTable(3);
                tableau.WidthPercentage = 100;
     
                // Cel du tableau
                AddCellToTab("Désignation", policeTh, blue, tableau);
                AddCellToTab("Quantité", policeTh, blue, tableau);
                AddCellToTab("Prix", policeTh, blue, tableau);
     
                // Lister les produits dans le tableau
                string[] infosProduit = new string[3];
                infosProduit[0] = nom.Text;
                infosProduit[1] = qte.Text;
                infosProduit[2] = prix.Text;
     
                foreach(string info in infosProduit)
                {
                    PdfPCell cell = new PdfPCell(new Phrase(info));
                    cell.BackgroundColor = gris;
                    cell.Padding = 7;
                    cell.BorderColor = gris;
                    tableau.AddCell(cell);
                }
     
                doc.Add(tableau);
                doc.Add(new Phrase("\n"));
     
                int prixTotal = int.Parse(prix.Text) * int.Parse(qte.Text);
     
                Paragraph p4 = new Paragraph("Total = " + prixTotal + "\n\n", policeTitre);
                p4.Alignment = Element.ALIGN_RIGHT;
                doc.Add(p4);
     
     
                // Fermer le document
                doc.Close();
                Process.Start(@"cmd.exe ", @"/c " + outfile);
            }
     
            public void AddCellToTab(string str, Font f, BaseColor c, PdfPTable t)
            {
                PdfPCell cell1 = new PdfPCell(new Phrase(str, f));
                cell1.BackgroundColor = c;
                cell1.Padding = 7;
                cell1.BorderColor = c;
                // cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                t.AddCell(cell1);
            }
        }
     
     
        }

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 126
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 126
    Points : 1 636
    Points
    1 636
    Par défaut
    Il semblerait que tu n'ai qu'un produit dans ton formulaire dans tes controles nom, qte et prix.

    Si tu as plusieurs produits où sont-ils ?

  3. #3
    Membre du Club
    Homme Profil pro
    Consultant Marketing
    Inscrit en
    Mars 2016
    Messages
    285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant Marketing
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2016
    Messages : 285
    Points : 57
    Points
    57
    Par défaut
    Citation Envoyé par umfred Voir le message
    Il semblerait que tu n'ai qu'un produit dans ton formulaire dans tes controles nom, qte et prix.

    Si tu as plusieurs produits où sont-ils ?
    Oui en effet et je voudrais avoir la possibilité d'avoir plusieurs produits et pour chaque produits avoir le total ?

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 126
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 126
    Points : 1 636
    Points
    1 636
    Par défaut
    bah c'est à toi de le concevoir ......

Discussions similaires

  1. Générateur de .pdf
    Par Shadam dans le forum VB.NET
    Réponses: 26
    Dernier message: 12/04/2011, 15h52
  2. Générateur de PDF xsl:fo compliant
    Par Nighty dans le forum Langage
    Réponses: 1
    Dernier message: 15/02/2009, 19h09
  3. Projet : générateur document PDF avec FPDF
    Par niki78 dans le forum Windows
    Réponses: 2
    Dernier message: 09/04/2008, 05h21
  4. Générateur de document HTML et PDF a partir d'un fichier XML
    Par Fildz dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 03/03/2006, 17h55

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