76,32 → 76,34 |
|
public static void createPdfFromXml(Source xmlFile, String xslFile, OutputStream pdfFile, Map<String, Object> params) throws IOException, FOPException, TransformerException { |
// configure fopFactory as desired |
System.out.println("1"); |
|
FopFactory fopFactory = FopFactory.newInstance(); |
|
System.out.println("2"); |
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); |
// configure foUserAgent as desired |
|
System.out.println("3"); |
// Setup output |
OutputStream out = new BufferedOutputStream(pdfFile); |
|
System.out.println("4"); |
// Construct fop with desired output format |
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); |
|
System.out.println("5"); |
// Setup XSLT |
|
Transformer transformer = getTransformer(xslFile,false); |
|
System.out.println("6"); |
if (params != null) |
for (Map.Entry<String, Object> entry : params.entrySet()) { |
transformer.setParameter(entry.getKey(), entry.getValue()); |
} |
|
System.out.println("7"); |
// Resulting SAX events (the generated FO) must be piped through to FOP |
Result res = new SAXResult(fop.getDefaultHandler()); |
|
System.out.println("8"); |
// Start XSLT transformation and FOP processing |
transformer.transform(xmlFile, res); |
|
System.out.println("9"); |
out.close(); |
} |
|