Guest User

Untitled

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. fopFactory.setUserConfig(new File("path/to/config.xml"));
  2.  
  3. fopFactory.getFontManager().setFontBaseURL(fontBase);
  4.  
  5. <dependency>
  6. <groupId>org.apache.xmlgraphics</groupId>
  7. <artifactId>fop</artifactId>
  8. <version>2.1</version>
  9. </dependency>
  10.  
  11. // setup xml input source
  12. String xml = object.toXml();
  13. StreamSource xmlSource = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));
  14.  
  15. // setup xsl stylesheet source
  16. File xslFile = new File(stylesheetPath);
  17. FileInputStream xslFileStream = new FileInputStream(xslFile);
  18. StreamSource xslSource = new StreamSource(xslFileStream);
  19.  
  20. // get transformer
  21. TransformerFactory tfactory = TransformerFactory.newInstance();
  22. Transformer transformer = tfactory.newTransformer(xslSource);
  23.  
  24. // setup FOP
  25. FopFactory fopFactory = FopFactory.newInstance(xslFile);
  26. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  27. foUserAgent.setProducer(this.getClass().getName());
  28. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, pdfContent);
  29.  
  30. // perform transformation
  31. Result res = new SAXResult(fop.getDefaultHandler());
  32. transformer.transform(xmlSource, res);
Add Comment
Please, Sign In to add comment