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

avec Java Discussion :

afficher et imprimer une liste en format PDF


Sujet :

avec Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Juillet 2007
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 11
    Points : 9
    Points
    9
    Par défaut afficher et imprimer une liste en format PDF
    Bonsoir tout le monde; j'essaie de faire une application en java et là je voudrais afficher une liste (en format PDF) d'enregistrements extraits de ma table (mysql) cela est il possible ?? merci d'avance

  2. #2
    Modérateur
    Avatar de XxArchangexX
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Mars 2012
    Messages
    1 159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 159
    Points : 2 323
    Points
    2 323
    Par défaut
    Bonsoir,

    Oui c'est possible . Pour le projet que j'ai fais j'ai utilisé itextpdf-5.1.3.jar qui te permet de faire cela. Par contre je le trouve moins puissante que le format XSL-FO avec le compilateur FOP qui transforme un fichier XML au format FO en PDF. Donc pour un truc de base tu peux utiliser le premier si tu cherches un peu plus pousser tu peux passer par le XML.

    Pour ma part je connais que c'est 2 méthodes . Si quelqu'un d'autre connait une autre méthode.

    Pour t'aider : c'est mon code brut je suis désolé pour mon non courage à le mettre en forme ^_^, mais tu peux l'étudier pour voir.
    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
     
    public void pdfFilmStockClient(){
    		pdfFilm();
    		/*for (Entry<String, String> film : list_film.entrySet()) {
    			System.out.println(film.getKey()+" >>> "+film.getValue());
    		}*/
    		// partie filmStock
    		String driver = "com.mysql.jdbc.Driver";           
    		String url = "jdbc:mysql://localhost:3306/locavideo";                     
    		String user = "root";       
    		String password = ""; 
    		com.itextpdf.text.Document document = new com.itextpdf.text.Document();
    		try {
    			PdfWriter.getInstance(document,new FileOutputStream("Administratif.pdf"));
    		} catch (FileNotFoundException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		} catch (DocumentException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
    		document.open();
     
    		try { 
    			//initialiser la pdf
    			//la parite produits
    			document.add(new Paragraph("          L'¨¦tat des stock par produit."));
    			document.add(new Paragraph(" "));
    			PdfPTable tab = new PdfPTable(7);
    			float one_WidthE[] = { 0.15f, 1.0f, 0.15f, 0.15f, 0.15f, 0.35f, 0.2f};	 
    			tab.setWidthPercentage(100);		 
    			tab.setWidths(one_WidthE);		 
    			tab.getDefaultCell().setPadding(0);
     
    			PdfPCell cell = new PdfPCell(new Phrase("Id"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("Nom"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("Prix"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("NbTotal"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("NbLocation"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("DateAjout"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);
    			cell = new PdfPCell(new Phrase("Etat"));
    			cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    			cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    			tab.addCell(cell);	
    			// connecter ¨¤ la base
    			Class.forName(driver);    
    			Connection conn = DriverManager.getConnection(url, user, password); 
    			if(!conn.isClosed()){
    				System.out.println("Succeeded connecting to the Database!"); 
    			}
    			Statement statement = conn.createStatement();
    			//System.out.println(film.getKey()+" >>> "+film.getValue());		
    			String sql = "SELECT * FROM film";             
    			ResultSet rs = statement.executeQuery(sql);    
    			while(rs.next()) {   
    				//System.out.println(rs.getString("Film_ID") + "\t" + rs.getString("Film_Prix") + "\t" + rs.getString("Film_NbExemplaireTotal"));
    				cell = new PdfPCell(new Phrase(rs.getString("Film_ID")));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				cell = new PdfPCell(new Phrase(list_film.get(rs.getString("Film_ID"))));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				cell = new PdfPCell(new Phrase(rs.getString("Film_Prix")));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				cell = new PdfPCell(new Phrase(rs.getString("Film_NbExemplaireTotal")));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				cell = new PdfPCell(new Phrase(rs.getString("Film_NbExemplaireEnLocation")));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				cell = new PdfPCell(new Phrase(rs.getString("Film_DateAjout")));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);
    				String supp;
    				if(rs.getString("Film_Supprime").contentEquals("0")){
    					supp = "supprim¨¦";
    				}else{
    					supp = "";
    				}
    				cell = new PdfPCell(new Phrase(supp));
    				cell.setHorizontalAlignment( com.itextpdf.text.Element.ALIGN_CENTER);
    				cell.setVerticalAlignment( com.itextpdf.text.Element.ALIGN_MIDDLE);
    				tab.addCell(cell);					
    			}
    			rs.close();	
    			document.add(tab);
                         document.close();
    }
    L'Etat est bien administré quand l'escalier de l'école est usé et que l'herbe croît sur celui du tribunal.

    Modérateur BI

Discussions similaires

  1. Afficher une liste de fichier pdf
    Par ledisciple dans le forum Webdesign & Ergonomie
    Réponses: 5
    Dernier message: 28/08/2008, 09h35
  2. Imprimer une liste de listes
    Par Ikit dans le forum Prolog
    Réponses: 1
    Dernier message: 14/12/2006, 18h39
  3. Générer une facture au format PDF
    Par lama85 dans le forum Langage
    Réponses: 1
    Dernier message: 21/08/2006, 18h46
  4. excel: colonne qui ne s'affiche pas dans une liste
    Par fast&furious dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 19/07/2006, 18h12
  5. [Rico] Afficher depuis d'une liste deroulante (PHP+AJAX)
    Par maxis dans le forum Bibliothèques & Frameworks
    Réponses: 9
    Dernier message: 27/02/2006, 12h47

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