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

Android Discussion :

Générer un PDF


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Par défaut Générer un PDF
    Bonsoir,

    Je veux générer une facture sous format PDF mais j'obtiens une erreur NoClassDefFoundError quand j'appelle la classe qui génère cette facture.

    J'ai lu pas mal de solutions concernant le Build Path. J'ai bien le dernier .jar iText dans le dossier libs de mon projet qui est exporté dans mon Build Path.

    Je ne comprends donc pas d'où pourrait venir l'erreur.

    Trace :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    02-25 15:09:15.548: E/AndroidRuntime(1194): FATAL EXCEPTION: main
    02-25 15:09:15.548: E/AndroidRuntime(1194): Process: com.example.test, PID: 1194
    02-25 15:09:15.548: E/AndroidRuntime(1194): java.lang.NoClassDefFoundError: com.example.test.Facture
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at com.example.test.ValidationCommande$1$2.onClick(ValidationCommande.java:215)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at android.os.Handler.dispatchMessage(Handler.java:102)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at android.os.Looper.loop(Looper.java:136)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at java.lang.reflect.Method.invokeNative(Native Method)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at java.lang.reflect.Method.invoke(Method.java:515)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    02-25 15:09:15.548: E/AndroidRuntime(1194): 	at dalvik.system.NativeStart.main(Native Method)

    Merci de l'attention que vous accorderez à mon problème,

    GJuubz

  2. #2
    Membre chevronné
    Avatar de provirus
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Février 2009
    Messages
    248
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2009
    Messages : 248
    Par défaut
    Selon l'exception
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.lang.NoClassDefFoundError: com.example.test.Facture
    le problème n'est pas dans la librairie iText, mais dans ton code personnel, plus précisément ta classe Facture qui n'est pas trouvée.

    Dans ce cas, il faudrait voir ton projet pour pouvoir t'aider.

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Par défaut
    Ma classe Facture :

    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
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    package com.example.test;
     
    import java.awt.BorderLayout;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
     
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Environment;
    import android.util.Log;
     
    import com.itextpdf.text.Document;
    import com.itextpdf.text.Element;
    import com.itextpdf.text.Image;
    import com.itextpdf.text.PageSize;
    import com.itextpdf.text.Paragraph;
    import com.itextpdf.text.pdf.PdfContentByte;
    import com.itextpdf.text.pdf.PdfPCell;
    import com.itextpdf.text.pdf.PdfPTable;
    import com.itextpdf.text.pdf.PdfWriter;
     
     
    public class Facture extends JFrame {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
    	String produit,quantite,prix;
     
    		private JTable table;
     
        public Facture() {
            getContentPane().setLayout(new BorderLayout());
            createTable();
        }
     
        public void createTable() {
            try {
     
              String quantitef;
                String produitf;
                String prixf;
     
                String col[] = {"Produit", "Quantité", "Prix unitaire"};
                String cont[][] = new String[10][3];
     
                for(int i = 0; i < ValidationCommande.listproduit.size() ; i++) {
     
                        quantitef = ValidationCommande.listproduit.get(i).get ("quantite");
                        produitf = ValidationCommande.listproduit.get(i).get ("produit");
                        prixf = ValidationCommande.listproduit.get(i).get ("prix");
     
                        cont[i][0] = produitf;
                        cont[i][1] = quantitef + "";
                        cont[i][2] = prixf + "";
     
                	}
     
                table = new JTable(cont, col);
     
                JPanel tPanel = new JPanel(new BorderLayout());
                tPanel.add(table.getTableHeader(), BorderLayout.NORTH);
                tPanel.add(table, BorderLayout.CENTER);
     
                getContentPane().add(tPanel, BorderLayout.CENTER);
     
            } catch (Exception e) {
            }
        }
     
     
    	public void genererPdf(String Nom, String Prenom, String Adresse, String Ville, String code_postal, String Email, String numCO, String date_commande, String Produit, String quantite, String prix, String prix_total) {
     
            Document doc = new Document(PageSize.A4);
     
     
            try {
     
            	String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PDF";
     
    			File dir = new File(path);
    			if(!dir.exists())
    				dir.mkdirs();
     
    			Log.d("PDFCreator", "PDF Path: " + path);
     
    			File file = new File(dir, "Facture_" + (numCO +1)+".pdf");
    			FileOutputStream fOut = new FileOutputStream(file);
     
    			PdfWriter writer = PdfWriter.getInstance(doc, fOut);
     
     
                //logo de l'entreprise
                /*Image img = Image.getInstance("C:/Users/Guillaume/Desktop/logo.jpg");
                img.scalePercent(20);
                img.setAlignment(Element.ALIGN_LEFT);
                
                	doc.add(img);*/
     
    			//coordonnées de l'entreprise
                Paragraph p = new Paragraph("BuyMe");
                p.setAlignment(Element.ALIGN_LEFT);
                Paragraph p1 = new Paragraph("10 rue de Rousseau");
                p1.setAlignment(Element.ALIGN_LEFT);
                Paragraph p2 = new Paragraph("75001 Paris");
                p2.setAlignment(Element.ALIGN_LEFT);
                Paragraph p3 = new Paragraph("contact@BuyMe.com");
                p3.setAlignment(Element.ALIGN_LEFT);
                p3.setSpacingAfter(30);
     
                	doc.add(p);
                	doc.add(p1);
                	doc.add(p2);
                	doc.add(p3);
     
    //date de la commande 
                Paragraph p4 = new Paragraph("Date de la commande : " + date_commande);
                p4.setSpacingAfter(10);
                p4.setAlignment(Element.ALIGN_LEFT);
     
    //coordonnées du client
                Paragraph p5 = new Paragraph(Nom + " " + Prenom);
                p5.setAlignment(Element.ALIGN_RIGHT);
                Paragraph p6 = new Paragraph(Adresse + " \n                 " + Ville + " " + code_postal);
                p6.setAlignment(Element.ALIGN_RIGHT);
                Paragraph p7 = new Paragraph(Email);
                p7.setAlignment(Element.ALIGN_RIGHT);
                p7.setSpacingAfter(15);
                Paragraph p8 = new Paragraph("Vous avez commandé : ");
                p8.setAlignment(Element.ALIGN_LEFT);
                Paragraph p9 = new Paragraph ("Pour un prix total de : " +prix_total+ " €");
              	p9.setAlignment(Element.ALIGN_CENTER);
              	p9.setSpacingBefore(10);
                Paragraph p10 = new Paragraph ("Vous trouverez ci-dessous le détail de votre commande :");
                p10.setAlignment(Element.ALIGN_LEFT);
                p10.setSpacingBefore(10);
     
                	doc.add(p5);
                	doc.add(p6);
                	doc.add(p7);
                	doc.add(p4);
                	doc.add(p8);
     
     
    //titre et numéro de commande              
                Paragraph p11 = new Paragraph("Facture n° " + numCO);
                p11.setAlignment(Element.ALIGN_CENTER);
                p11.setSpacingBefore(20);
                p11.setSpacingAfter(30);
     
    //création du tableau
                 PdfPTable table = new PdfPTable(4);
     
                 PdfPCell cell1 = new PdfPCell(new Paragraph("Produit"));
                 cell1.setGrayFill(0.8f);
                 cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                 table.addCell(cell1);
     
                 cell1 = new PdfPCell(new Paragraph("Prix unitaire (€)"));
                 cell1.setGrayFill(0.8f);
                 cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                 table.addCell(cell1);
     
                 cell1 = new PdfPCell(new Paragraph("Quantité"));
                 cell1.setGrayFill(0.8f);
                 cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                 table.addCell(cell1);
     
                 cell1 = new PdfPCell(new Paragraph("Prix total (€)"));
                 cell1.setGrayFill(0.8f);
                 cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                 table.addCell(cell1);
     
     
                    for(int i = 0; i < ValidationCommande.listproduit.size() ; i++) {
     
                	 String quantiteF = ValidationCommande.listproduit.get(i).get ("quantite");
                     String produit = ValidationCommande.listproduit.get(i).get ("produit");
                	 Paragraph p12 = new Paragraph("               "+ quantiteF +" "+produit);
                	 p12.setAlignment(Element.ALIGN_LEFT);
                     	doc.add(p12);
     
                	 int t = Integer.parseInt(ValidationCommande.listproduit.get(i).get ("prix")) * Integer.parseInt(ValidationCommande.listproduit.get(i).get ("quantite"));
                     String total = String.valueOf(t);
                     String prix_unité = ValidationCommande.listproduit.get(i).get ("prix");
                     String quantity = ValidationCommande.listproduit.get(i).get ("quantite");
                     String Produitt = ValidationCommande.listproduit.get(i).get ("produit");
     
                     PdfPCell cell2 = new PdfPCell(new Paragraph(prix_unité));
                     cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
     
                     PdfPCell cell3 = new PdfPCell(new Paragraph(quantity));
                     cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
     
                     PdfPCell cell4 = new PdfPCell(new Paragraph(total));
                     cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
     
     
                	 table.addCell(Produitt);
                	 table.addCell(cell2);
                	 table.addCell(cell3);
                	 table.addCell(cell4);
     
                 }
     
     
                 	doc.add(p10);
                 	doc.add(p11);
     
     
                 	doc.add(table);
                 	doc.add(p9);
     
                            PdfContentByte cb = writer.getDirectContent();
     
                cb.saveState();
     
    			Graphics2D g2 = cb.createGraphicsShapes(500, 500);
     
                Shape oldClip = g2.getClip();
                g2.clipRect(0, 0, 500, 500);
     
                //table.print(g2);
                g2.setClip(oldClip);
     
                g2.dispose();
                cb.restoreState();
     
                doc.close();
     
     
            } catch (Exception e) {
                System.out.println(e);
            }
     
        }
     
    }
    Là où je l'appel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    .......................
           builder2.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
     
                         		@Override
                         		public void onClick(DialogInterface arg0, int arg1) {
                         			// TODO Auto-generated method stub     			                    			
     
                         		 Facture g = new Facture();
                                     g.pack();
                                     g.genererPdf(nom, prenom, adresse, ville, code_postal, Cemail, NumCO, date_commande, produit, quantite, prix, prix_total);
     
                            ...............................
    Les 2 classes sont dans le même package, je sais pas quelles informations de plus vous avez besoin ^^

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2009
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2009
    Messages : 141
    Par défaut
    Swing dans Android, c'est nouveau ça

  5. #5
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Par défaut
    Ca pique les yeux en Android !!!

  6. #6
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Ca risque pas de marcher, c'est sur

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

Discussions similaires

  1. Générer un PDF en Java
    Par joneil dans le forum Documents
    Réponses: 7
    Dernier message: 25/02/2012, 15h14
  2. Générer du PDF avec QuickReport
    Par yanis97 dans le forum Composants VCL
    Réponses: 11
    Dernier message: 29/07/2008, 16h59
  3. Générer un PDF à partir d'une page ASP
    Par Poussy-Puce dans le forum ASP
    Réponses: 1
    Dernier message: 30/03/2006, 17h45
  4. Générer du pdf
    Par illegalsene dans le forum Documents
    Réponses: 5
    Dernier message: 04/05/2005, 14h20
  5. Librairies gratuites pour générer du PDF
    Par Noxexplorer dans le forum ASP
    Réponses: 2
    Dernier message: 02/05/2005, 20h18

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