|
Rank: Member
Joined: 12/17/2013 Posts: 14
|
Hi,
could i use a java aplication to generate pdf files without open StyleVision? I mean that StyleVision is unseen to the user
Any ideas?
|
|
Rank: Advanced Member
Joined: 7/17/2008 Posts: 185 Location: Minutiae, Triviality
|
You use StyleVision to generate an XSLT file, then use altovaxml.exe to process the input XML using that XSLT file. The output is a pdf description which has to be passed through another processor. You can use FOP (from Apache) to generate an output .pdf file using the intermediate output.
StyleVision used to create XSLT template
XSLT+XML and an xsl processor (like altovaxml.exe) to create the pdf xml description (XSL-FO)
XSL-FO and FOP to create the pdf.
Once you have the XSLT from StyleVision, you no longer need StyleVision for that PDF output (since you can change the XML input instance, so long as it matches the same XSD as the one used to design the XSLT template in the first place).
If you are using Java, and expect it to be cross platform, you will need to use xslt1 or find a java-based xslt2 processor (since altovaxml is not cross platform... or is it? that may have changed...see my .sig below). You will also need a java based FOP, which the Apache one is, but you will need to figure out how to use it from inside a Java application (I've never done this but it should be doable).
let us know how you get on!
rip
|
|
Rank: Member
Joined: 12/17/2013 Posts: 14
|
Thank You for the answer
|
|
Rank: Member
Joined: 10/23/2013 Posts: 18
|
If you still need this, here is a basic method that will do what you require using FOP as the PDF generator and XALAN as the XSLT processor, given you set the XSLT level to 1.0 in StyleVision.
If you require XSLT 2.0 then the only viable option I know is Saxon, but the only Schema-Aware versions are the paid ones, so if at all possible I'd recommend staying with XSLT 1.0 for Java usage.
Obviously you will need to have the various FOP jars on your classpath, but aside from that Xalan is bundled with the JVM itself.
Code: /** * Render a source XML file to a PDF layout using FOP and Xalan. * * @param xml the source XML Stream. * @param xsltStream the xslt file stream to be used for XML to XSL-FO. * @param out the Output Stream where FOP will write. * */ public void renderXMLtoPDF(StreamSource xml, StreamSource xsltStream, OutputStream out) { try { // configure fopFactory as desired fopFactory = getFopfactory(); // configure foUserAgent as desired FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); // Start XSLT transformation and FOP processing // Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(xsltStream); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // 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(xml, res); } catch (FOPException e) { logger.error("SAX Error detected during PDF creation", e); } catch (TransformerException ex) { logger.error("Transformer Error detected during PDF creation", ex); } }
|
|
guest |