How to Convert HTML to PDF

Hello everybody, recently I written a code for converting HTML to PDF. Initially, I thought of using iText PDF library to generate PDF file as an attachment while sending emails to the user. When I started working on it one of my team members told me that iText is no more open source. Without even knowing the actual details like from which version iText is not Open Source, I started using PDFBox jars for PDF related operations.

Even though PDFBox is one of the good libraries, I felt difficult to align the things inside PDF if content is changing dynamically. So, I thought of using some techniques like converting Image to PDF or HTML to PDF to avoid alignment problems but of no luck.

Finally, I started reading about iText license, based on information provided in wikipedia, I came to know that till 2.1.7 iText is available under LGPL, then again I started using iText for HTML to PDF convertion.

Following are the Code snippets for  HTML to PDF Conversion :

  1. Maven Dependency Details:
    <dependency>
     <groupId>commons-io</groupId>
     <artifactId>commons-io</artifactId>
     <version>0.1</version>
     </dependency>
     <dependency>
     <groupId>com.lowagie</groupId>
     <artifactId>itext</artifactId>
     <version>2.1.7</version>
     </dependency>
    
    <dependency>
     <groupId>org.xhtmlrenderer</groupId>
     <artifactId>flying-saucer-pdf</artifactId>
     <version>9.0.1</version>
     </dependency>
    
  2. Code to convert HTML to PDF:

Content in this post has been moved,  please Click Here…  for new location of the actual content

Sorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

Please follow me in the new website www.dailypaper.in/technical for more technical stuff.

Ajax request processing using Spring MVC 3.X

Are you trying to integrate DWR and Spring MVC 3.X? If your answer is yes, then you’re wasting valuable development time in fixing integration problems.
May be it is good to have DWR library for Ajax calls while developing a web application, but when you are using Spring MVC3 for developing your application this is not a good solution, because Spring Frame work itself capable for handling Ajax Calls. In this article, I would like to explain

Basic way of handling Ajax calls using Spring MVC:

  1. Dependency configuration:
    <dependency>
    
    <groupId>org.springframework</groupId>
    
    <artifactId>spring-beans</artifactId>
    
    <version>3.1.3.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework</groupId>
    
    <artifactId>spring-context</artifactId>
    
    <version>3.1.3.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework</groupId>
    
    <artifactId>spring-web</artifactId>
    
    <version>3.1.3.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework</groupId>
    
    <artifactId>spring-webmvc</artifactId>
    
    <version>3.1.3.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework</groupId>
    
    <artifactId>spring-core</artifactId>
    
    <version>3.1.3.RELEASE</version>
    
    </dependency>
    
     
  2. Server Side Coding: The code below describes how to write a Controller to process asynchronous requests.
    Content in this post has been moved,  please Click Here…  for new location of the actual contentSorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

    Please follow me in the new website www.dailypaper.in/technical for more technical stuff.

Integrating DWR3 and Spring3

Exceptions while integrating DWR3 and Spring3.X annotation based MVC:

Following are the solutions for the Exception commonly occur while integration:

  1. “org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionParser for element [annotation-scan]“.

Solution:

  • Don’t use  DWR with version number  DWR 3.0M1(available in Maven Repository)

Content of this website has been moved to new location please Clicke Here…  to continue reading in the new location.

Sorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

Please follow me in the new website www.dailypaper.in/technical for more technical stuff.

 2.If you are trying to keep DWR and Spring Configuration in the same xml file there may be a chance to occur duplicate name found Exception.
 
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘DwrAnnotationURLMapper’:
Initialization of bean failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘dwrController’:
Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException:
java.lang.IllegalArgumentException:
Duplicate name found

 Solution: keep separate dwr.xml and don’t import into spring-config.xml file instead configure in web.xml as shown below

Content of this website has been moved to new location please Clicke Here…  to continue reading in the new location.

Sorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

Please follow me in the new website www.dailypaper.in/technical for more technical stuff.

 
3. No adapter for handler [org.directwebremoting.spring.DwrController@1b3f577]: Does your handler implement a supported interface like Controller?

Solution: keep the following line of code in dwr.xml file

Content of this website has been moved to new location please Clicke Here…  to continue reading in the new location.

Sorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

Please follow me in the new website www.dailypaper.in/technical for more technical stuff.

Struts Facebook Integration

Now a days people are using Facebook like any thing, you can do many things with Facebook like sharing photos, writing on friends wall, chatting, playing games and more.

As it is becoming popular day by day some of the firms or individuals trying to do marketing with the help of Facebook and some are doing business by integrating their applications with the Face book. For example online recharge with this you can do recharge for your Facebook friends as a gift or you can request a Facebook friend to recharge your mobile.

To do this kind of integration, our applications should be hosted some where on the web and need to be integrated with Facebook. To achieve this, Facebook has provided some of the concepts like

In this article we are using struts based web application to integrate with Facebook with the help of above mentioned concepts.

Steps to configure your Application with Facebook:

 

Content of this website has been moved to new location please  Click Here…  to continue reading in the new location.

 

Sorry for the inconvenience. Please click the above link to continue to read.This is all because the content has been moved to the new website www.dailypaper.in/technical/.

 

Please follow me in the new website www.dailypaper.in/technical for more technical stuff.