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 :

Transformer un xml en pdf


Sujet :

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

  1. #1
    Membre confirmé 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
    Par défaut Transformer un xml en pdf
    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
    <?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 Expert
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    1 466
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 1 466
    Par défaut
    Il te demande de configurer le loggueur sur lequel fop pourra envoyer ses messages, donc faut faire un truc du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Logger log = null;
    log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
    MessageHandler.setScreenLogger(log);

  3. #3
    Membre confirmé 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
    Par défaut
    Merci Morbo pour ta réponse, mais ça marche tjs pas avec ce que tu m'as envoyé pourant il s'agit bien d'un problème de logger (t'as tout à fait raison là dessus).

    Mais bon, j'ai trouvé un autre truc sur le net qui est bien fait. (ça pourrait peut être interesse quelqu'un.

    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);
            }
        }
    }
    Bon courage.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Août 2006
    Messages : 9
    Par défaut ca devrait résolver ton problème
    j'avais le même soucis, en fait le paramètre doit être defini comme ca :

    URI - representing the base URI. The URI should be fully resolved.
    For example:
    "http://www. xmlmill.com/test/" or
    "file:///c:/xmlmill/test/"

    dans mon cas j'avais oublié "file:///" devant mon chemin.

    et ca marche

  5. #5
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 2
    Par défaut PDF > XML, c'est possible?
    Bonjour à tous,
    je ne suis pas certain d'être au bon endroit, mais je cherche à faire l'inverse du sujet de ce TOPIC:
    Transformer un PDF en XML.
    Il existe des fonctions d'export dans Acrobat du PDF en XML, mais les données récupérées dans le XML sont en "vrac " (du moins il met tous les blocs à la suite sans que je puisse savoir quel bloc est sur quelle page) et j'aimerais en récupérer un peu plus...
    Du style taille et positions des blocs images et textes par exemple ainsi que la page à laquelle ils appartiennent.

    Quelqu'un sait il si il existe un logiciel qui réaliserait l'export du PDF vers XML avec un peu plus d'infos que l'export à partir d'Acrobat?

    Ou pensez vous qu'il y a moyen de réaliser un retraitement du XML réalisé à partir d'Acrobat, et d'en tirer un peu plus que ce qu'il me donne actuellement?

    D'avance, merci pour toutes vos suggestions.

  6. #6
    Membre Expert
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    1 466
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 1 466
    Par défaut
    C'est plutôt difficile, le PDF est un format optimiser pour l'impression, la sémantique du document y est très dégradée.
    Je ne connais pas d'outil le faisant.
    Cependant, tu peux regarder itext qui est, à la connaissance, le seul outil opensource te permettant d'extraire les info brutes d'un PDF.
    Si tu trouves des solutions, laisse quelques pointeurs ici, ça m'interesse.
    Bon courage!

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

Discussions similaires

  1. Transformation d'un Docbook xml en PDF
    Par prince_antonio dans le forum Struts 1
    Réponses: 1
    Dernier message: 06/11/2007, 00h58
  2. Transformer XML en PDF par XSLT
    Par abda1000 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 12/06/2007, 17h10
  3. Réponses: 7
    Dernier message: 04/06/2007, 15h51
  4. [FOP] Transformation XML to PDF par FOP
    Par JustAGphy dans le forum Format d'échange (XML, JSON...)
    Réponses: 13
    Dernier message: 12/05/2004, 15h19
  5. transformer un fichire Xml en pdf
    Par SuperFoustan dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 21/02/2003, 11h45

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