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 :

creation d'un fichier pdf à partir d'un fichier xml


Sujet :

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

  1. #1
    Membre du Club Avatar de med_ellouze
    Profil pro
    Étudiant
    Inscrit en
    Mai 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 52
    Points
    52
    Par défaut creation d'un fichier pdf à partir d'un fichier xml
    bonjour,

    Voilà j'essaye de creer un fichier pdf à partir d'un fichier xml.
    J'ai vu qu'il y a déjà un exemple sur la FAQ mais le problème c'est que j'arrive pas à le faire marcher sur mon ordi.

    Voilà, j'ai pris le meme fichier xml
    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
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <annuaire>
    	<personne id="0">
    		<nom>nom0</nom>
    		<prenom>nom0</prenom>
    		<adresse>adresse0</adresse>
    	</personne>
    	<personne id="1">
    		<nom>nom1</nom>
    		<prenom>nom1</prenom>
    		<adresse>adresse1</adresse>
    	</personne>
    	<personne id="2">
    		<nom>nom2</nom>
    		<prenom>nom2</prenom>
    		<adresse>adresse2</adresse>
    	</personne>
    	<personne id="3">
    		<nom>nom3</nom>
    		<prenom>nom3</prenom>
    		<adresse>adresse3</adresse>
    	</personne>
    	<personne id="4">
    		<nom>nom4</nom>
    		<prenom>nom4</prenom>
    		<adresse>adresse4</adresse>
    	</personne>
    </annuaire>
    le même fichier XSL
    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
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    	<xsl:template match="/">
    		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" 
    					xmlns:fox="http://xml.apache.org/fop/extensions">
    			<fo:layout-master-set>
    				<fo:simple-page-master master-name="all"
    										page-height="29.7cm" 
    										page-width="21cm"
    										margin-top="1cm" 
    										margin-bottom="2cm" 
    										margin-left="2.5cm" 
    										margin-right="2.5cm">
    					<fo:region-body margin-top="3cm" margin-bottom="3cm"/>
    					<fo:region-before extent="3cm"/>
    					<fo:region-after extent="2.5cm"/>
    				</fo:simple-page-master>
    			</fo:layout-master-set>
     
    			<fo:page-sequence master-reference="all">
    				<fo:static-content flow-name="xsl-region-before">
    					<xsl:call-template name="entete"/>	
    				</fo:static-content> 
    				<fo:static-content flow-name="xsl-region-after">
    					<xsl:call-template name="basDePage"/>
    				</fo:static-content> 
    				<fo:flow flow-name="xsl-region-body">
    					<fo:block>
    						<xsl:call-template name="miseEnPage"/>
    					</fo:block>
    				</fo:flow>
    			</fo:page-sequence>
    		</fo:root> 
    	</xsl:template>
     
    	<xsl:template name="entete">
    		<fo:block text-align="center" 
    					font-size="8pt" 
    					line-height="10pt"
    					border-bottom="#D1D7DC"
    					border-bottom-style="solid"
    					border-bottom-width="1pt"
    					padding-top="2pt"
    					padding-right="2pt"
    					padding-left="2pt"
    					padding-bottom="2pt">
    					HAUT DE PAGE
    		</fo:block>
    	</xsl:template>
     
    	<xsl:template name="miseEnPage">
    		<xsl:apply-templates select="annuaire"/>
    	</xsl:template>
     
    	<xsl:template match="annuaire">
    		<fo:block>
    			ANNUAIRE	
    		</fo:block>
    		<fo:block>
    			Actuellement, <xsl:value-of select="count(personne)"/> personnes dans l'annuaire.	
    		</fo:block>
    		<fo:block>
    			<fo:table table-layout="fixed" width="80%">
    				<fo:table-column column-width="proportional-column-width(1)"/>
    				<fo:table-column column-width="proportional-column-width(1)"/>
    				<fo:table-column column-width="proportional-column-width(1)"/>
    				<fo:table-column column-width="proportional-column-width(1)"/>
    				<fo:table-header>
    					<fo:table-row font-weight="bold" 
    									text-align="center" 
    									vertical-align="middle"
    						  			background-color="#A6A5C2">
    						<fo:table-cell border="black"
    									border-style="solid"
    									border-width="1pt">
    							<fo:block>ID</fo:block>
    						</fo:table-cell>
    						<fo:table-cell border="black"
    									border-style="solid"
    									border-width="1pt">
    							<fo:block>Nom</fo:block>
    						</fo:table-cell>
    						<fo:table-cell border="black"
    									border-style="solid"
    									border-width="1pt">
    							<fo:block>Prenom</fo:block>
    						</fo:table-cell>	
    						<fo:table-cell border="black"
    									border-style="solid"
    									border-width="1pt">
    							<fo:block>Adresse</fo:block>
    						</fo:table-cell>	
    					</fo:table-row>	
    				</fo:table-header>
    				<fo:table-body>
    					<xsl:apply-templates select="personne"/>
    				</fo:table-body>
    			</fo:table>	
    		</fo:block>
    	</xsl:template>
     
    	<xsl:template match="personne">
    		<fo:table-row>
    			<fo:table-cell border="black"
    							border-style="solid"
    							border-width="1pt">
    				<fo:block>
    					<xsl:value-of select="@id"/>
    				</fo:block>
    			</fo:table-cell>
    			<fo:table-cell border="black"
    							border-style="solid"
    							border-width="1pt">
    				<fo:block>
    					<xsl:value-of select="nom"/>
    				</fo:block>
    			</fo:table-cell>
    			<fo:table-cell border="black"
    							border-style="solid"
    							border-width="1pt">
    				<fo:block>
    					<xsl:value-of select="prenom"/>
    				</fo:block>
    			</fo:table-cell>
    			<fo:table-cell border="black"
    							border-style="solid"
    							border-width="1pt">
    				<fo:block>
    					<xsl:value-of select="adresse"/>
    				</fo:block>
    			</fo:table-cell>
    		</fo:table-row>	
    	</xsl:template>
     
    	<xsl:template name="basDePage">
    		<fo:block text-align="center" 
    					font-size="8pt" 
    					line-height="10pt"
    					border-top="#D1D7DC"
    					border-top-style="solid"
    					border-top-width="1pt"
    					padding-top="2pt"
    					padding-right="2pt"
    					padding-left="2pt"
    					padding-bottom="2pt">
    			<fo:block>
    				BAS DE PAGE - <fo:page-number/> -
    			</fo:block>
    		</fo:block>
    	</xsl:template>
    </xsl:stylesheet>
    et biensure la même classe JAVA
    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
    import javax.xml.parsers.*; 
    import org.w3c.dom.*; 
    import org.xml.sax.*; 
    import javax.xml.transform.*; 
    import javax.xml.transform.sax.*; 
    import javax.xml.transform.dom.*; 
    import javax.xml.transform.stream.*; 
    import java.io.*; 
    import java.util.*; 
    import org.apache.fop.apps.Driver;
    public class CreationPDF{
    	public static void creerPDF(String xml, String xsl, String pdf) throws Exception{
    		// création du résultat (pdf)
    		Driver driver = new Driver();
    		driver.setRenderer(Driver.RENDER_PDF);
    		driver.setOutputStream(new java.io.FileOutputStream(pdf));
    		Result resultat = new SAXResult(driver.getContentHandler());
     
    		// récupération de la source xml
    		Source source = new StreamSource(xml);
     
    		// création du transformer en fonction du xsl
    		Source style = new StreamSource(xsl);
    		TransformerFactory transformerFactory = TransformerFactory.newInstance();
    		Transformer transformer = transformerFactory.newTransformer(style);
     
    		// transformation
    		transformer.transform(source, resultat);
    	}
    	public static void main(String[] args){
    		try{
    			creerPDF("Annuaire.xml", "AnnuaireFOP.xsl", "Annuaire.pdf");
    		}catch(Exception e){e.printStackTrace();}
    	}
    }
    J'ai bien installé la librairie FOP, mais au moment de la compilation j'ai des erreurs.Voilà ce qui m'affiche sur la console :
    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
    [ERROR] Logger not set
    javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:805)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    Caused by: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1002)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	... 2 more
    Caused by: javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:996)
    	... 3 more
    Caused by: java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	... 3 more
    ---------
    javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1002)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    Caused by: javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:996)
    	... 3 more
    Caused by: java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	... 3 more
    ---------
    javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:996)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    Caused by: java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	... 3 more
    ---------
    java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    ---------
    java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    ---------
    javax.xml.transform.TransformerException: java.net.MalformedURLException: unknown protocol: c
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:996)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    Caused by: java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	... 3 more
    ---------
    java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    ---------
    java.net.MalformedURLException: unknown protocol: c
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at java.net.URL.<init>(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:972)
    	at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)
    	at fichierMRX91.CreationPDF.creerPDF(CreationPDF.java:43)
    	at fichierMRX91.CreationPDF.main(CreationPDF.java:52)
    J'ai cherché un peu sur le forum, mais j'ai pas vraiment trouvé une réponse à cette question. Merci pour votre aide.

  2. #2
    Membre du Club Avatar de med_ellouze
    Profil pro
    Étudiant
    Inscrit en
    Mai 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 52
    Points
    52
    Par défaut
    Je me suis peut être mal exprimé.

  3. #3
    Membre du Club Avatar de med_ellouze
    Profil pro
    Étudiant
    Inscrit en
    Mai 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2006
    Messages : 89
    Points : 52
    Points
    52
    Par défaut
    St tout le monde,
    Bon je viens de résoudre le prob, Voilà un code qui permet de transformer un xml en pdf.
    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
    public class XmlToPdf {
     
        public void convertXML2PDF(File xml, File xslt, File pdf) 
                    throws IOException, FOPException, TransformerException {
            //Construct driver
            Driver driver = new Driver();
     
            //Setup logger
            Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
            driver.setLogger(logger);
            MessageHandler.setScreenLogger(logger);
     
            //Setup Renderer (output format)        
            driver.setRenderer(Driver.RENDER_PDF);
     
            //Setup output
            OutputStream out = new java.io.FileOutputStream(pdf);
            try {
                driver.setOutputStream(out);
     
                //Setup XSLT
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(new StreamSource(xslt));
     
                //Setup input for XSLT transformation
                Source src = new StreamSource(xml);
                System.out.println("Xml input :"+xml);
                System.out.println("Xsl input :"+xslt);
     
                //Resulting SAX events (the generated FO) must be piped through to FOP
                Result res = new SAXResult(driver.getContentHandler());
     
                //Start XSLT transformation and FOP processing
                transformer.transform(src, res);
     
                System.out.println("Pdf output :"+out.toString());
     
            } finally {
                out.close();
            }
        }
     
     
        public static void main(String[] args) {
            try {
                System.out.println("FOP ExampleXML2PDF ");
                System.out.println("Preparing...");
     
                //Setup directories
                File baseDir = new File(".");
                File outDir = new File(baseDir, "out");
                outDir.mkdirs();
     
                //Setup input and output files          
                File xmlfile = new File(baseDir, "xml/xml/projectteam.xml");
                File xsltfile = new File(baseDir, "xml/xslt/projectteam2FO.xsl");
                File pdffile = new File(outDir, "ResultXML2PDF.pdf");
     
                System.out.println("Input: XML (" + xmlfile + ")");
                System.out.println("Stylesheet: " + xsltfile);
                System.out.println("Output: PDF (" + pdffile + ")");
                System.out.println();
                System.out.println("Transforming...");
     
                XmlToPdf app = new XmlToPdf();
                app.convertXML2PDF(xmlfile, xsltfile, pdffile);
     
                System.out.println("Success!");
            } catch (Exception e) {
                System.err.println(ExceptionUtil.printStackTrace(e));
                System.exit(-1);
            }
        }
    }
    Allez bon courage, j'espère que ça peut aider quelqu'un.

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

Discussions similaires

  1. Macro Ouverture de plusieurs fichiers PDF à partir d'un fichier Excel ?
    Par Mounamidou dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 01/12/2009, 18h53
  2. Creation Fichier PDF à partir d'un MAIL
    Par sormiou dans le forum VBA Outlook
    Réponses: 5
    Dernier message: 18/07/2007, 13h09
  3. [JDBC]ouvrir un fichier pdf à partir d'un blob
    Par souletis dans le forum JDBC
    Réponses: 5
    Dernier message: 25/01/2007, 21h03
  4. [ java.net ] récupérer un fichier PDF à partir d'une URL
    Par nico2280 dans le forum Entrée/Sortie
    Réponses: 7
    Dernier message: 10/11/2005, 11h09
  5. Réponses: 9
    Dernier message: 20/06/2005, 16h47

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