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

Format d'échange (XML, JSON...) Java Discussion :

récuperation des données xml dans un fichier PDF


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 8
    Points : 11
    Points
    11
    Par défaut récuperation des données xml dans un fichier PDF
    Bonsoir tout le monde ,j'ai une application dont je dois génerer un fichier PDF ,et j'utilise itext comme API , mais j'ai un probleme lorsque je veux recuperer une donnée dans un fichier xml qui est la base donnée de notre application et la placer dans une paragraphe de mon fichier PDF.
    voila une partie de code:


    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
    public class HelloWorld {
     
        /** Path to the resulting PDF file. */
        public static final String RESULT
            = "C:/Users/bobmed/Documents/NetBeansProjects/HelloWorld/hello.pdf";
     static org.jdom2.Document doc;
        /**
         * Creates a PDF file: hello.pdf
         * @param    args    no arguments needed
         */
      static org.jdom2.Element racine;
      /*
     java.util.List listEtudiants = racine.getChildren("professeur");
     Iterator i = listEtudiants.iterator();
     org.jdom2.Element courant = (org.jdom2.Element)i.next();
     */
    
        public static void main(String[] args)
        	throws DocumentException, IOException {
            SAXBuilder sxb = new SAXBuilder();
    try
    {
    doc= sxb.build(new File("ensao.xml"));
    }
    catch(Exception e){}
      new HelloWorld().createPdf(RESULT);
     racine = doc.getRootElement();
     
           
    
        }
     
        /**
         * Creates a PDF document.
         * @param filename the path to the new PDF document
         * @throws    DocumentException 
         * @throws    IOException 
         */
        public void createPdf(String filename)
    	throws DocumentException, IOException {
                 java.util.List listEtudiants = null;
                 listEtudiants=racine.getChildren("professeur");
                 Iterator i = listEtudiants.iterator();
                 while(i.hasNext()){
                 final org.jdom2.Element courant = (org.jdom2.Element)i.next();
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter.getInstance(document, new FileOutputStream(filename));
            // step 3
            document.open();
            // step 4;
            PdfPTable table1 = new PdfPTable(1);
            PdfPCell cell = null;
            cell = new PdfPCell(new Phrase("DESCREPTIF DU MODULE",new Font(Font.FontFamily.HELVETICA, 22)));
            cell.setBackgroundColor(BaseColor.PINK);
            table1.addCell(cell);
            document.add(table1);
            document.add(new Paragraph(courant.getChild("prof_nom").getText()));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("Université:                Mohammed 1er"));
            document.add(new Paragraph("Etablissement:          Ecole national des sciences appliquées Oujda"));
            document.add(new Paragraph("Departement  :          Genie informatique"));
            document.add(new Paragraph("Intitulé de module:     Programmation orienté objet C++"));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
            document.add(new Paragraph("          "));
      
            Paragraph title = new Paragraph ("Important",
                      new Font (Font.FontFamily.HELVETICA, 20,
                             Font.BOLD | Font.UNDERLINE,BaseColor.BLUE));
              title.setAlignment (Element.ALIGN_CENTER);
              title.setSpacingAfter (15.0f);
              document.add (title);
            document.add(new Paragraph("1. Ce formulaire, dûment rempli pour chaque module de la filière, doit être joint à la demande d’accréditation de la filière         "));
            document.add(new Paragraph("2. Adapter les dimensions des tableaux aux contenus"));
            document.add(new Paragraph("3. Joindre des annexes en cas de besoin."));
    quand j'éxecute le projet il me donne l'erreur suivante :


    Exception in thread "main" java.lang.NullPointerException
    at helloworld.HelloWorld.createPdf(HelloWorld.java:61)
    at helloworld.HelloWorld.main(HelloWorld.java:45)
    Java Result: 1
    Merci de m'aider.

  2. #2
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 551
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 551
    Points : 21 607
    Points
    21 607
    Par défaut
    Il manque trop de choses.

    Montre-nous un truc court (notamment, si le problème est avec XML, ça ne sert à rien de nous montrer du PDF.)
    Un truc court, mais qui compile.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Réponses: 0
    Dernier message: 09/03/2010, 20h17
  2. Exporter des données xml dans un fichier XHTML
    Par StAfX dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 02/02/2009, 15h21
  3. [XHTML 1.0] Importer des données XML dans fichier XHTML
    Par StAfX dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 27/01/2009, 14h09
  4. récupérer des données saisies dans un fichier
    Par natie_49 dans le forum C++
    Réponses: 6
    Dernier message: 24/11/2005, 11h29
  5. [JList] Lecture des données sauvegardées dans un fichier
    Par Myogtha dans le forum Composants
    Réponses: 7
    Dernier message: 10/06/2004, 21h05

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