Process an XSL-FO Document

Process an XSL-FO Document

Sometimes you need to process an XSL-FO document that is the result of an XSLT transformation. Actually, the XSL-FO document doesn’t exist, it is just a stream of SAX events. In a Java application, this can be done with the FOP processor classes:

//the XML documentC:Data_LocalxmldocsAirWings_xpath_xslt.xml//the XSL stylesheetC:Data_LocalxmldocsAirWings_xslt_fop.xsl//the output - a PDF fileC:Data_LocalxmldocsAirWings_xslt_1.pdf//FOPimport org.apache.fop.apps.Driver; import org.apache.fop.messaging.MessageHandler;//Avalonimport org.apache.avalon.framework.logger.Logger;import org.apache.avalon.framework.logger.ConsoleLogger;//Javaimport java.io.*;import javax.xml.transform.*;import javax.xml.transform.stream.*;import javax.xml.transform.sax.SAXResult;public class XSL_FO_and_XML_XSLT_1{   public static void main(String[] args)      {      OutputStream OS_pdf=null;      Transformer tXML=null;               //create a org.apache.fop.apps.Driver object      Driver fop=new Driver();              //setting  a logger      Logger logger=new ConsoleLogger(ConsoleLogger.LEVEL_INFO);      fop.setLogger(logger);      MessageHandler.setOutputMethod(MessageHandler.SCREEN);      MessageHandler.setScreenLogger(logger);             //specify the PDF format      fop.setRenderer(Driver.RENDER_PDF);                                         //the PDF file      try{         File F_pdf=new File                ("C://Data_Local//xml//docs//AirWings_xslt_1.pdf");         OS_pdf=new FileOutputStream(F_pdf);            fop.setOutputStream(OS_pdf);         }catch(java.io.FileNotFoundException e)            {MessageHandler.error("[***   "+e.getMessage()+"                                    ***]");}                                                 //create a TransformerFactory object      TransformerFactory tfXML=TransformerFactory.newInstance();               //setting the XSL stylesheet, AirWings_xslt_fop.xsl      Source sXSL=new StreamSource(new File              ("C://Data_Local//xml//docs//AirWings_xslt_fop.xsl"));                      //getting a Transformer object      try{         tXML=tfXML.newTransformer(sXSL);         }catch             (javax.xml.transform.TransformerConfigurationException e)            {MessageHandler.error("[*** XSLT Error ***]");}               //setting the XML, AirWings_xpath_xslt.xml      Source sXML=new StreamSource(new File             ("C://Data_Local//xml//docs//AirWings_xpath_xslt.xml"));               //define the Result      Result rXML=new SAXResult(fop.getContentHandler());      //pass sXML and rXML to the transformer      try{         tXML.transform(sXML,rXML);         }catch(javax.xml.transform.TransformerException e)            {MessageHandler.error("[*** XSLT error ***]");}      }}         

Notice that there isn’t an .fo/.fop file.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes