JBoss JMX Collection: how to create a PDF from text
Starting from now we will collect all interesting MBeans and POJO Services and make available to readers. In this tutorial we will show a POJO Service that transforms a text file into a PDF table using the iText library
The prerequisite of this sample is the iText library which needs to be downloaded from:
http://itextpdf.com/
iText is an ideal library for developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation.
-
Download the iText1.2.X.jar library and add to the application server library path.
To create a service POJO all you need is adding a few annotations to your POJO Class, which will act as a singleton service.
Here's the service POJO Class:
What is really interesting about the POJO service are the two annotations:
@Service(objectName = "textToPdf:service=PDFConverter")
@Management(PDFConverter.class)
With the first one (@Service) you are binding the POJO in the textToPdf domain using the PDFConverter service name
The Second annotation (@Management) contains the interface name which will be exposed to the client. The interface is nothing more than a plain Java interface:
@Service(objectName = "textToPdf:service=PDFConverter")
@Management(PDFConverter.class)
With the first one (@Service) you are binding the POJO in the textToPdf domain using the PDFConverter service name
The Second annotation (@Management) contains the interface name which will be exposed to the client. The interface is nothing more than a plain Java interface:
The real class which does the job of converting a text file into a PDF formatted table is PDFCreator which basically reads the input file name stores the content into an Array using the "|" as separator between fields.
Deploying the Service POJO is just a matter of packaging the files into a JAR archive and copying the archive into the deploy folder of JBoss AS. The following output will be produced on the JBoss AS Console:
17:04:36,364 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=JBossServiceP DF.jar,name=PDFConverterService,service=EJB3 17:04:36,364 INFO [JBossASKernel] with dependencies: 17:04:36,380 INFO [JBossASKernel] and supplies: 17:04:36,380 INFO [JBossASKernel] Class:com.sample.PDFConverter 17:04:36,380 INFO [JBossASKernel] jndi:PDFConverterService/remote 17:04:36,380 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=JBossServicePDF.jar ,name=PDFConverterService,service=EJB3) to KernelDeployment of: JBossServicePDF.jar 17:04:36,427 INFO [EJBContainer] STARTED EJB: com.sample.PDFConverterService ejbName: PDFConverterService |
For testing the POJO Service you can navigate to the JMX Console and add the input and output file name:

This is a sample of input file:
column1|column2|column3
aaaaaaa|bbbbbbb|ccccccc
ddddddd|eeeeeee|fffffff
ggggggg|hhhhhhh|iiiiiii
This is the PDF output:

Resources:
Service POJO Tutorial
column1|column2|column3
aaaaaaa|bbbbbbb|ccccccc
ddddddd|eeeeeee|fffffff
ggggggg|hhhhhhh|iiiiiii
This is the PDF output:

Resources:
Service POJO Tutorial

