Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fopFactory.setUserConfig(new File("path/to/config.xml"));
- fopFactory.getFontManager().setFontBaseURL(fontBase);
- <dependency>
- <groupId>org.apache.xmlgraphics</groupId>
- <artifactId>fop</artifactId>
- <version>2.1</version>
- </dependency>
- // setup xml input source
- String xml = object.toXml();
- StreamSource xmlSource = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));
- // setup xsl stylesheet source
- File xslFile = new File(stylesheetPath);
- FileInputStream xslFileStream = new FileInputStream(xslFile);
- StreamSource xslSource = new StreamSource(xslFileStream);
- // get transformer
- TransformerFactory tfactory = TransformerFactory.newInstance();
- Transformer transformer = tfactory.newTransformer(xslSource);
- // setup FOP
- FopFactory fopFactory = FopFactory.newInstance(xslFile);
- FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
- foUserAgent.setProducer(this.getClass().getName());
- Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, pdfContent);
- // perform transformation
- Result res = new SAXResult(fop.getDefaultHandler());
- transformer.transform(xmlSource, res);
Add Comment
Please, Sign In to add comment