Bonjour, j'aimerais passer 3 variables à savoir:
Une premier qui est le chemin xml
Une autre qui est le xsl
Enfin, la dernière est le chemin du pdf qui doit être créer.

Voici mon code, j'ai un errreur et je ne sais pas pourquoi:

PS: Le fopFactory est bien initialisé avec FopFactory.newInstance()

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	public void convert(File xml, File xslt, File pdf) throws IOException, FOPException, TransformerException {
		// Setup output
		OutputStream out = new java.io.FileOutputStream(pdf);
 
		try {
			// Init FOP
			Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
 
			// Generate
			PDFGenerator.convertXML2PDF(xml, xslt, fop);
		} finally {
			out.close();
		}
	}
La méthode: convertXML2PDF:

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
	public static void convertXML2PDF(File xml, File xslt, Fop fop) throws FOPException, TransformerException {
 
		// Setup XSLT
		TransformerFactory factory = TransformerFactory.newInstance();
		Transformer transformer = factory.newTransformer(new StreamSource(xslt));
 
		// Setup input for XSLT transformation
		Source src = new StreamSource(xml);
 
		// Resulting SAX events (the generated FO) must be piped through to
		// FOP
		Result res = new SAXResult(fop.getDefaultHandler());
 
		// Start XSLT transformation and FOP processing
		transformer.transform(src, res);
	}


Merci