Convert Excel to PDF Java Servlet Example

In this tutorial, we will provide a Java Servlet, that will accept a user uploaded Microsoft Excel document, and convert the Excel sheet data into a table in a PDF document. We will also demonstrate the ability to transform both XLS and XLSX extension files to PDF through the servlet. Some high level notes about this servlet are given below:

XLS to PDF Servlet – Notes


  • The servlet can accept both XLS and XLSX files as input.
  • The user will specify what type of file is uploaded.
  • Apache POI v3.8 would be used to read the user uploaded file.
  • iText 5.3.4 would be used to convert the uploaded file to PDF document.
  • The servlet will be hosted in Apache TomCat 6.0.36
  • apache-commons-fileupload-1.2.2 and apache-commons-io-2.4 will be used to convert the user uploaded file to InputStream.
  • By default we will assume the excel data is located in the first sheet in columns A and B. Though, this can be sent as an input the servlet if required.
I will not be covering the steps to configure the servlet in Apache TomCat. You can use this tutorial as a reference if you want to setup Apache to work with the servlet.

Excel to PDF Servlet – Steps


Following are the high level steps in this tutorial:
  • Design HTML form to support XLS to PDF transformation.
  • Download required Java libraries for conversion.
  • How to handle the uploaded Excel file in Servlet?
  • Complete Java Servlet Code.
  • Servlet configuration / Testing in TomCat.
You can follow this example step by step or directly jump to a specific section by following the links below:

This Tutorial Series: Convert Excel to PDF – Java Servlet Example
Keywords: Excel to PDF, Java Servlet, Apache POI, Itext, Convert XLS to PDF Example
All parts:
1. HTML Form Design to support XLS to PDF Conversion.
2. JAR Files required for conversion and their use.
3. Handling uploaded file in a servlet./ Complete Java code to convert Excel to PDF through a servlet.
4. Servlet Configuration / Testing.

No comments: