One might thing what is the benefit to convert XML to PDF as XML is used in a variety of application even today. One of the drawbacks of XML is that it lacks in the presentation and aesthetic features. In this regards it makes useful to convert XML to PDF documents.
One can convert XML to PDF by using formatting objects processor (FOP), and Ant. They both are Apache projects. So by using both the Apache projects here are the following steps of the process to convert XML to PDF:
In the first step of the process to convert XML to PDF, you need to convert the XML fragment to an XSL-FO tree. To have specific conversion instructions for every XML element you will require style sheet. To construct the tree, XSL-FO element used is the most basic in nature. FOP also offers fancier formatting elements for the documents.
After the above step, next we will prepare the Ant script so can do the actual conversion. With this you also have to keep in mind that you also have to create the directory called lib that contains the FOP’s libraries. This is important to place the build. xml file. The additional JARS and the fop.jar files are the files that are included in the FOP download. These files are located in build and lib directories.
The Ant script than first describes the path instruction which loads all the FOP’s libraries, that is located in the lib directory. After this the main target is set which we call the PDF. In this our first declaration is named al fop which contains the actual logic for converting the XSL-FO tree to the PDF format.
After this we declare another task called xslt task. This task takes two input parameters, one is the in=linuxdistros.xml and other is style=”linuxdistrod2pdf.xsl”. The first one deals with the XML files while the second one corresponds to the XSL style sheet. The output of this task is named as out=linuxdistros.fo. In this whatever the output is generated is placed in this file. It also represents the XSL-FO tree. This also defines the fop task in which the XSL-FO tree linuxdistros.fo is taken and a PDF file is generated called linuxdistros.pdf.
In the end the Ant PDF command is executed from the shell to generate the PDF document.
So you can now directly convert XML to PDF document by using these open source based tools.
So now we have learned that to convert XML to PDF, FOP is a good source.
There are many outsourcing company that offers the HTML to PDF conversion, HTML to Excel at an affordable rate. It will help you in converting any type of HTML file to the required PDF file. To ensure that the quality is maintained it is rechecked by experts. You will find the HTML to PDF conversion very beneficial to you.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment