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
| // Step 1: Construct a FopFactory
// (reuse if you plan to render multiple documents!)
System.out.println("step 1");
// Step 2: Set up output stream.
// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
System.out.println("step 2");
String file_name="C:\\Users\\fichier.pdf";
OutputStream out1 = new BufferedOutputStream(new FileOutputStream(file_name));
request.setAttribute("fichier",fichier);
// Step 3: Construct fop with desired output format
System.out.println("step 3");
FopFactory fopFactory = FopFactory.newInstance();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out1);
// Step 4: Setup JAXP using identity transformer
System.out.println("step 4");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer1 = factory.newTransformer(); // identity transformer
// Step 5: Setup input and output for XSLT transformation
// Setup input stream
System.out.println("step 5");
String chaine=out.toString();
//StringReader src = new StringReader(chaine);
//InputSource source=new InputSource(src);
Source src = new StreamSource(chaine);
// Resulting SAX events (the generated FO) must be piped through to FOP
System.out.println("step 6");
Result res = new SAXResult(fop.getDefaultHandler());
System.out.println("step 61");
// Step 6: Start XSLT transformation and FOP processing
transformer1.transform(src,res);
System.out.println("fin de transformation");} |
Partager