August 16, 2007

Creating PDF files through Java

PDF has become a very popular interchange format for text and graphical documents and are used in electronic publishing. Abobe's PDF format has penetrated into the market extensively and this format has a big market share. Initially, it was designed as a "final" document format, but the dynamic requirements of document exchange over the Internet led to dynamic PDFs and also other formats. You will find many other formats like excel sheets, word documents dynamically created on net to deliver reports, results, product comparisons etc. So, lets have a look at creating PDF files dynamically.
As a java programmer you should be able to create PDF files in web applications and standalone applications once you finish this article. In the end I will also explain how to convert other documents to PDF online and also how to make options for creating PDFs of your blog or webpage.

PDF libraries:

You can find many libraries both commercial and open-source that will help you create PDF files.I will consider only open-source libraries here and particularly one library: iText. Apart from this library you have gnujpdf, JFreeReport, PJX etc...

As I said iText is a open-source pure Java class library for creating and manipulating PDF documents. It provides a rich set of features like support for both PDF and FDF documents, different layouts, images, document encryption, watermarks, document templates etc. Its published in two different licenses: MPL and LGPL.

On to Coding...

Like I said, I will be looking into iText library for now.. Let's get started. Upon downloading and extracting the compressed file, you will have a single jar file which holds all the necessary classes. There are two major classes in creating a PDF file, they are Document and PdfWriter. Document represents your programmatic PDF file and the writer helps you to associate the document object with any output stream. So you can directly write to a file system or transfer the PDF through a servlet's output stream. Now lets look into a simple method that will create a PDF file on file system:

public void createTestPdf() throws FileNotFoundException {
Document pdfDocument = new Document();
String filePath = "c:\\" + fileName;
FileOutputStream fos = new FileOutputStream( filePath );

PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(pdfDocument, fos);
writer.open();
pdfDocument.addTitle("A sample PDF Title");
pdfDocument.addAuthor("Abdel");
pdfDocument.open();
pdfDocument.add(new Paragraph("This is a sample PDF document created using iText PDF library!"));
pdfDocument.add(Image.getInstance("C:\\Documents and Settings\\My Documents\\My Pictures\\puzzle.jpg"));
pdfDocument.add(new Paragraph("This is second Paragraph"));
pdfDocument.close();
writer.close();
}catch (DocumentException e) {
System.out.println("Document Exception!");
e.printStackTrace();
}
}

The above method createTestPdf will create a simple PDF file with some text and image. The API is quite simple.

Online PDF tools:

There are many online PDF tools available to create and convert files. Adobe provides PDF conversion for a fee, but lets look into some other alternatives. PDF Online provides two services: Doc2PDF Online and Web2PDF Online. Web2PDF Online is still in BETA and I will talk about it too.. but, first Doc2PDF. It gives you the facility to convert different documents like word document, excel sheets, power point slides, HTML etc to be converted online in three steps. Upload the documents, give the output filename and email address to which the converted document is to be sent.

Now onto web2PDF Online service. This helps you to convert your blog or website into PDF files. Your visitors can quickly save their useful information with a click of a button. To avail this service you have to create a account with PDF Online. They also track your site's PDF conversions. I tried it on my testing blogs and found some small glitches, like the quality and page size. But overall the service is good.

August 05, 2007

Blueprint, a CSS Framework

We have frameworks for everything today, starting from core programming frameworks to web and Ajax frameworks. Mentioning these frameworks will give us a endless list. Now, I am going to introduce a new framework, and this is a CSS framework called Blueprint!

The main aim of this framework is to cut down on your CSS development time. It gives you a solid CSS foundation to build your project on top of, with an easy-to-use grid, sensible typography, and even a stylesheet for printing. This framework is still young and not completely tested...

The framework is distributed with MIT license and is a result of Olav Bjørkøy's hard work. I will try this out and may be write about this framework again (About its usage and adaptability). Right now let me get back and enjoy my weekend!

August 03, 2007

Applying Themes to your Flex Application

Themes for the UI attract the user very much. You will find may of the UI libraries being made skinnable. One such example is the new YUI 2.3.0 where Yahoo have added skinning capability to YUI library. I am going to talk about themes in Flex here. This blog entry is basicaly a reply to one of the comment I reveiced after writing about styles in Flex applications.

Themes in Flex can be in many forms. Flex themes are in three forms: simple CSS file, SWF or SWC file.Lets take each of these one after the other.

CSS file Themes:
This is one of the easy way arround to apply themes. If you have the CSS file you can set the style or skin using the <mx:Style> tag. I have written about the CSS styles and you can have a look here!

SWC file Themes:
Themes also take the form of SWC files. These file contain style sheets and the images as assets. This is the major benifit of SWC files over CSS. In case of CSS files you need to carry the assets seperatly. SWC file make it easier to distribute and is precompiled.

To apply the theme to your Flex application you need to user the theme compiler option. When you compile a application using the mxmlc you can use the theme option to specify the theme that you require to apply on the application. For example

mxmlc -theme C:/flex_sdk/themeTest/sample.swc -file-specs themedFlex.mxml

Another way to provide the theme during compilation is to make use of the <theme> tag in flex-config.xml file.

For more information on this check the online flex reference!

SWF file Themes:

You can use SWF files to hold sikn assets and refer them from the Flex application. A SWF file can hold one of more assets and you can embed the required element using the Embed statement as follows:

<mx:Style>
Button {
upSkin: Embed(source="../assets/SubmitButtonUpSkin.swf");
}
</mx:Style>

To embed a perticular symbol from the SWF file you can use the symbol property to specify the symbol. An example is shown below:

<mx:Style>
Button {
upSkin: Embed(source='../assets/SubmitButtonSkins.swf', symbol='MyUpSkin');
}
</mx:Style>

So regarding themes.. that's all for now.. Ah hold on.. you can download some Flex themes from here. Have a look, They are great!

Online Video Converter

I have been looking for something like this for some time now. How do you convert and download video that you see in YouTube, Google videos etc? Here is the solution.. FLVIX!

The conversion is quite simple. All you have to do is paste the video URL in the text field provided and select the result format that you need. The video get converted to that format and you will have it downloaded. There are five formats: AVI, MOV, MP4, 3GP, MP3 (Audio).

So, if you have a list of favorite videos that you need downloaded.. go get IT!

Ext Releases version 1.1

I have been keeping tabs on this library for some time. After I found the v1.1’s candidate release few weeks ago, I have been learning how to built interface using the Ext library. So, what’s new with the Ext 1.1? You can download the new version here.

The new release includes stand-alone version of Ext, a lightweight HTML editor, a new Ext.Ajax utility class, enhancements to DateField and DatePicker, expanded documentation and bug fixes. Out of this the major advancement that you will see the is the stand-alone base library. Now Ext no longer requires you to use a 3rd party library like YUI or Prototype, but you still have the option to make use of the 3rd party libraries if required.

Another major advancement is the new WYSIWYG html editor. The main idea was to make an html editor that integrates well with the other Ext components and also keep it extremely light weight. The new editor is said to be only 12k in size and easily customizable. For a demo check this out.

The other enhancement that will catch your eye is the new Ajax utility class. The Ext.Ajax provides features to handle global Ajax events. These events includes queuing and combining Ajax requests into a single call, cancel requests, provide data locally, add parameters, etc. I will look in-depth to this matter as I will be using this Ajax class. :)

Now regarding the documentation, I still don’t find any tutorial that will kick start a new developer and make him adapt Ext easily. I would say the API documentation is really good but still need improvement when it comes to beginners. But for now,I will download the v1.1 and start playing.

August 01, 2007

Adobe AIR Application list

AIR applications have started appearing and they are coming up fast. Last week I spotted a IM Messenger built using AIR and is pretty good! Here is a list of AIR applications that I found few minutes ago. Its built in wiki and anybody can add a new application to the list. At present the list is about 78 and I am sure this will grow.

For all the Adobe AIR enthusiast, this list will give you a good collection of AIR applications!

Link to the list : http://airapps.pbwiki.com/FrontPage

Well, if you have missed the train, I suggest you check these links out:

Adobe AIR : http://labs.adobe.com/technologies/air/

AIR Resource : http://www.airapps.net/ (You will get all the resource from this site!)