IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

StyleVision with Java Options · View
Edi4988
Posted: Tuesday, December 17, 2013 6:04:02 PM
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?
rip
Posted: Wednesday, December 18, 2013 12:32:08 AM
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
Edi4988
Posted: Thursday, January 23, 2014 4:03:02 PM
Rank: Member

Joined: 12/17/2013
Posts: 14
Thank You for the answer
Irian
Posted: Monday, January 27, 2014 5:06:37 PM
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);
      }
   }
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.