Generating PDF reports using nfop
Generating PDF reports using nfop
Free Online Articles Directory
Why Submit Articles?
Top Authors
Top Articles
FAQ
ABAnswers
0 && $.browser.msie ) {
var ie_version = parseInt($.browser.version);
if(ie_version Login
Register
Hello
My Home
Sign Out
Email
Password
Remember me?
Lost Password?
Home Page > Computers > Programming > Generating PDF reports using nfop
Generating PDF reports using nfop
Posted: Jun 09, 2010 |Comments: 0
| Views: 161 |
]]>
Written by:
Petro Vodopyan, Intern developer of Device Team,
Introduction
There are lots of articles, which describe how to convert XML documents to the documents of other types using the XSL Formatting Objects. Most of them describe how to obtain HTML from XML and only few tell about PDF documents.
Such articles usually demonstrate simple examples (how to build the table or perform the text output). But sometimes we need to create representative reports or documents. In this case, developers face nontrivial problems â for example creating the table of contents (using internal or external links), bookmark trees, picture galleries, etc. Â This article will help you to examine main features of XSL schemes.
Brief survey of the topic
Generation of PDF documents is based on the Apache XML FOP technology that was initially written in Java language. But in our case, we use  nFOP â the C# wrapper that is based on the Visual J#. This wrapper makes it easier to write pure .NET reporting modules. The generation of PDF documents is very simple and can be described in the following way:
We have an XML document (created by some application or manually) and  XSLT scheme, with the help of which we obtain the XSL-FO document. The PDF file will be created on its basis. Then we compile the obtained XSL-FO document to PDF with the help of FOP.
С# example
The process of PDF document generation can be described using a small example. Supposing, there is a list of writers, who have their books and these books consist of articles, respectively:
This structure is represented by Author and Book classes.
public class Author { public List created; public string name; public int id; … } public class Book { public int id; public Props bookProps; public List articles; … }
C# language allows you to serialize any class to XML document. In this case, we can provide the following example:
//Serializing data FileStream fs = System.IO.File.Create(“source.xml”); XmlSerializer s = new XmlSerializer(typeof(List)); List list = new List(); list.Add(writer); list.Add(writer1); s.Serialize(fs, list); fs.Close();
Then, according to the scheme described above, the process of XLS-FO document generation is performed:
//Generate FO file XslTransform xslt = new XslTransform(); //Loading XSL template xslt.Load(“schema.xsl”); //Loading XSL template xslt.Transform(“source.xml”, “source.fo”);
The last step is to call the methods of nfop, which compiles XLS-FO to PDF:
//Generate PDF file java.io.FileInputStream streamFO = null; java.io.FileOutputStream streamOut = null; try { streamFO = new java.io.FileInputStream(“source.fo”); streamOut = new java.io.FileOutputStream(fileName + “.pdf”); InputSource src = new InputSource(streamFO); Driver driver = new Driver(src, streamOut); driver.setRenderer(Driver.RENDER_PDF); driver.run(); } catch(FOPException ex) { Console.WriteLine(ex.Message); throw; } catch (System.Exception ex) { Console.WriteLine(ex.Message); throw; } finally { if (streamOut != null) { streamOut.close(); } if (streamFO != null) { streamFO.close(); } }
It is important to include the following references to the solution being developed:
vjslib
nfop
vjslib.dll can be downloaded here.
nfop.dll can be downloaded here.
XSL Features
As it was mentioned above, the majority of articles about XSL-FO describe such common things as the output of the formatted text or the creation of tables. But often you need to add to the document:
Table of contents with internal references to articles (taking into account that we do not know the page numbers beforehand as the document is generated dynamically)
The bookmark tree (rather convenient tool for navigating in the document)
Footnotes with definite blocks of the text and, perhaps, references to external web pages
The picture gallery (it can be also dynamically saved by means of the C# language).
The bookmark tree.
Table of contents with internal references to chapters of the document.
Page numbering.
Static picture (can be the company logo).
Brief survey of main XSL operators and constructions
XSL language includes all main constructions:
if analog:
<!–Operations–> switch analog:
<!–Operations–> <!–Operations–> for analog (processes a number of XML nodes with the same level of nesting):
<!–Operations–>
You can access the definite node by index (if you know its number in the list beforehand):
Also you can use some variable as the index:
…
number($index) conversion returns the number, which was generated from the string stored in $index. If you do not use it, the $index variable will possess “1” as any  value as is considered to be of the string type by default.
If you use the position() operator it’s better to check also the condition:
…
Here, position() is the number of the current node of the XML document (last() is the last in the list, respectively).
Usage of Cyrillic and East Asian fonts
There is often a problem of using specific languages in reports. By default, they are not included in the list of nfop fonts. To add new languages, you have to add a new font to the useconfig.xml file. The configuratiob file will look like the following:
Here, metrics-file is a path to the font metric, embed-file is a path to the font file.
In the example above, the standard arialuni.ttf font was added. It is a part of Windows OS (WINDOWS\Fonts\ARIALUNI.TTF) and is the most universal one. Fonts should be placed in the same folder as the configuration file.
Building the bookmarks tree
When building the bookmark tree (with references to the articles), you should specify an additional id field in the nodes. With its help, references will be organized in the XSLT scheme.
We can create the static class, which generates unique id for each object that we need to refer on later:
public static class IDGenerator { private static int id = 0; public static int Generate() { return id++; } }
Labels to refer on are placed when building the tables. We just add one more attribute to the current block, which will be used in references:
The process of building the tree is based on placing the blocks of such type:
<!–Name of bookmark–>
They can be placed as the nested ones and it will create the treelike structure.
Building the table of contents
The table of contents of the document is created in the similar way. The same id field (as in the previous example) is used for references:
Chapter 1<!–Name of link–>
The line fills space between the text and page number by dots.
Â
Page numbering
One more interesting moment is that we do not know exactly on which page the table will be located while building the PDF document. Here we can use an expression that will define the page number of the dynamically generated document automatically:
Logo insertion
XSL Templates allow you to create the static content in any page region that will be repeated on each page. For example, the following code inserts the logo to the lower right corner of the document:
<!– logo in lower right part of report page–>
The building of the document frame can be organized in the similar way. You need to create four separate images for each border of the document (top, bottom, left and right), which can be then used as the background of the region  (region-after, region-before, region-end, region-start).
Hyperlink insertion
To insert external references, you can use the following construction:
Table rotation
There is often a problem of displaying the tables with numerous columns. Such tables cannot be placed within the page borders.
Name
Prop1
Prop2
Prop3
â¦
PropN
1
Some data
Some data
Some data
â¦
Some data
2
Some data
Some data
Some data
â¦
Some data
In this case, it is possible to perform table rotation, where a new table will correspond to each row:
Table 1 â first row
Name
1
Prop1
Some data
Prop2
Some data
Prop3
Some data
â¦
â¦
PropN
Some data
Table 2 â second row
Name
2
Prop1
Some data
Prop2
Some data
Prop3
Some data
â¦
â¦
PropN
Some data
Sometimes there is a nonstandard situation when it is necessary to process the data, which is stored in two related lists of nodes of the XML document. For example, you need to fill in the table where the first column Columns contains the name of the data, the second one – Rows – contains its values.
Name Phone Number Johny 555-55-55 Â Â Â Â Â Ann 333-60-00
To create the table from the given XML document, you can use the following pattern:
Gallery
The process of creating the picture gallery can be described in the following way:
The required pictures are saved to the temporary folder on the hard drive (programmatically).
The XML document is created. It contains the full paths and the description of the saved files (this data will be used later in the XSLT scheme).
The PDF document is generated. Pictures from the temporary folder are built in it.
The temporary folder with its contents is deleted.
Name Blue hills Path E:/pdf_root/Blue hills.jpg Size 28Â 521 bytes Type JPG File Created 12 may 2010, 15:01:36 …
The pattern, which builds the gallery, is given below:
Gallery
As a result, we receive the following table:
Conclusion
In this article, we introduced a brief description of creating the PDF report using the existing data in the program. Also we gave a brief survey of main constructions and operators of the XSL language. There are a lot of simple but rather nonstandard situations when we need to transpose tables, move between levels in the XML document, and create picture galleries.
For additional information, see the following links:
http://www.renderx.com/tutorial.html
http://www.w3schools.com/xslfo/
http://www.ecrion.com/Support/PDF/XSL-FOTutorial.pdf
Â
I hope that this article will be useful while developing your applications.
Retrieved from “http://www.articlesbase.com/programming-articles/generating-pdf-reports-using-nfop-2588833.html”
(ArticlesBase SC #2588833)
Start increasing your traffic today just by submitting articles with us, click here to get started.
Liked this article? Click here to publish it on your website or blog, it’s free and easy!
Apriorit –
About the Author:
Apriorit Inc. is a provider of professional consulting and software development services.
]]>
Questions and Answers
Ask our experts your Programming related questions here…
200 Characters left
Which ranking tool do you use for seo client management, rank reporting? I’ve used Rank Checker which is decent. Any strong suggestions? I’ve seen Advanced Web Reporting
Is solar power generator an environmental friendly equipment? I read sunpowerportcom and find some useful information. What do you think?
What are electric generators used for?
Rate this Article
vote(s)
0 vote(s)
Feedback
RSS
Print
Email
Re-Publish
Source: http://www.articlesbase.com/programming-articles/generating-pdf-reports-using-nfop-2588833.html
Article Tags:
xsl, generate pdf, c pdf, create pdf report
Latest Programming Articles
More from Apriorit
All vendors in the enterprise document composition market who use XSL-FO claim it is an âopen standardâ and that makes their solution superior, more modern and customer oriented than proprietary ones. That dear analysts, vendors and customers is a straightforward misrepresentation. Most vendors seem to believe that the use of an XML-like structure proves a kind of elevated status of intelligence or a future oriented technology.
By:
Max J. Pucherl
Computers>
Information Technologyl
Mar 10, 2009
lViews: 632
Internet Explorer – Slurry Pump EHR – china Sludge Pump EZG
Overview Internet Explorer was first released as part of the add-on package Plus! for Windows 95 in 1995. Later versions were available as free downloads, or in service packs
By:
xiao5096rl
Business>
Agriculturel
Aug 08, 2010
Make customer friendly ecommerce solutions
Having an ecommerce solutions web site is not enough these days, but a good, comfortable and amazingly functional website is required.
By:
Sritikantha Pattnaikl
Computers>
Programmingl
Feb 14, 2011
Now what do you want to develop your website in Joomla now you can moderate plan as per your needs. Joomla focuses your attention on Joomla CMS Website Developers. The website development companies have their own expert Joomla developers and designers.
By:
Savinderl
Computers>
Programmingl
Feb 14, 2011
A Few Obvious Reasons to Choose Drupal Development over Other CMSs
Apart from being a powerful CMS, Drupal has loads of positive features that make it a hot favorite of Web developers. This article explores the reasons behind the soaring popularity of this CMS against other Content Management Systems.
By:
webspidersl
Computers>
Programmingl
Feb 14, 2011
Customize Your iPod/iPhone Design With Custom Skin Design Software
Custom skin design software application is the best way to customize iPod/iPhone design. In this article, benefits of using iPod/iPhone with custom skin design software have been discussed for vinyl skins.
By:
Devashish Kumarl
Computers>
Programmingl
Feb 14, 2011
Why are Web Solutions in Demand?
The World Wide Web has opened up all new boulevards to ever increasing prospects for business and has come up as a major channel for knowledge and communication. Every business wants its presence to be felt in the online world by reaching to larger number of audience and is planning and to create an online domain through which all internet users can be reached. This is where internet based solutions or web solutions come into play. The customized solutions on web helps individuals grow in their
By:
Shriv Commedial
Computers>
Programmingl
Feb 14, 2011
Mobile Application Development Technology and Its Implementation Area
Today Smartphone is hybrid of computer and mobile phone. In this article, I am scrutinizing current mobile technology and its implementation area.
By:
Kelly Burbyl
Computers>
Programmingl
Feb 14, 2011
Key elements of Effective website design
There are a lots of details to be considered while designing a web site.
By:
dubainetsolutionsl
Computers>
Programmingl
Feb 11, 2011
IPhone: Smart Phones with variety of Apps at Apple Inc
iPhone application development is in great demand and is one of the most productive businesses today.Because of its open paltform a lot of experimentations can be done with iPhone application development. The launch of software development kit or SDK has further provided impetus to the iPhone developer to create a range of customized applications for their users.
By:
mobileprogrammingl
Computers>
Programmingl
Feb 11, 2011
Testing Strategies for the Software Virtualization Systems
In this article, we will examine the specific of testing of the software virtualization systems. We will touch upon the following questions: * test environment configuration; * testing types; * nuances of each of testing types for the virtualization systems. So, we will examine those important things that should be taken into account when thinking over the testing strategy of the software virtualization system.
By:
Aprioritl
Computers>
Softwarel
Oct 04, 2010
Exchange Server: Express Configuration for Testing
This article can be useful for those testers who configure their test environment themselves without the help of the system administrator. The aim of the article is to present a step-by-step description of the installation and configuration of the domain controller, Exchange Server, and MS Outlook with two accounts for the testing purposes.
By:
Aprioritl
Computers>
Softwarel
Oct 04, 2010
User mode transport of the library via virtual channels
In this article, we provide the library which can be used in client â server applications to cover transport layer using virtual channels. Also we attached sample add-in project (client side) and sample server application.
By:
Aprioritl
Computers>
Programmingl
Jun 11, 2010
How to test virtual desktop acceleration in the LAN and WAN configurations
This article is devoted to the testing of programs that use virtual desktop acceleration to improve performance. Here we will consider features of virtualization, testing scenarios, some useful tools and tips, and also will give examples of real test cases.
By:
Aprioritl
Computers>
Programmingl
Jun 04, 2010
Porting an application from one platform (Windows) to another (Linux) is an interesting topic. First, knowledge of several platforms and writing the code for them is a good experience for every developer. Secondly, writing an application for different platforms makes it widespread and needed by many. So, I would like to share my impressions concerning this process. This article is intended for everybody who wants to write a cross-platform application.
By:
Aprioritl
Computers>
Programmingl
May 18, 2010
Port Monitor: How to receive the number of document copies during the printing
In this article, we will examine a problem of receiving the correct value of the dmCopies variable in the DEVMODE structure while printing from Microsoft Word 2003. This can be useful for the case of writing a program that controls printing (to printers, as well as to files).
By:
Aprioritl
Computers>
Programmingl
May 18, 2010
The testing report as the powerful tool of the optimization of the software development process
If you prepared the testing reports without making the preliminary analysis of the findings before, please start doing it. The correctly prepared report on the results of testing is a powerful tool for the optimization of the software development process. That is why let’s pay special attention to this process. This article includes practical recommendations concerning the preparation of different types of testing reports and their ready examples.
By:
Aprioritl
Computersl
May 18, 2010
Implementation Of Diffie-Hellman Algorithm Of Key Exchange
The article is devoted to the development of the library that implements the Diffie â Hellman cryptographic algorithm of key exchange. The library appeared as a result of the necessity to use the Diffie â Hellman algorithm without the involvement of any third-party libraries.
By:
Aprioritl
Computers>
Securityl
Apr 02, 2010
lViews: 279
Add new Comment
Your Name: *
Your Email:
Comment Body: *
Verification code:*
* Required fields
Submit
Your Articles Here
It’s Free and easy
Sign Up Today
Author Navigation
My Home
Publish Article
View/Edit Articles
View/Edit Q&A
Edit your Account
Manage Authors
Statistics Page
Personal RSS Builder
My Home
Edit your Account
Update Profile
View/Edit Q&A
Publish Article
Author Box
Apriorit has 19 articles online
Articles Categories
All Categories
Advertising
Arts & Entertainment
Automotive
Beauty
Business
Careers
Computers
Education
Finance
Food and Beverage
Health
Hobbies
Home and Family
Home Improvement
Internet
Law
Marketing
News and Society
Relationships
Self Improvement
Shopping
Spirituality
Sports and Fitness
Technology
Travel
Writing
Computer Forensics
Computer Games
Data Recovery
Databases
E-Learning
File Types
Hardware
Information Technology
Intra-net
Laptops
Networks
Operating Systems
Programming
Security
Software
]]>
Need Help?
Contact Us
FAQ
Submit Articles
Editorial Guidelines
Blog
Site Links
Recent Articles
Top Authors
Top Articles
Find Articles
Site Map
Mobile Version
Webmasters
RSS Builder
RSS
Link to Us
Business Info
Advertising
Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2011 Free Articles by ArticlesBase.com, All rights reserved.
Apriorit Inc. is a provider of professional consulting and software development services.
a walk around the block
Video Rating: 0 / 5