HTML Form Design – XLS to PDF Servlet

We are covering how to convert an Excel document table to a table in PDF document using Java servlet API. In this part, we will explain how to design a HTML form that will accept a file and post it to the server.

Identify Servlet Input Elements:


To design the form, we need to identify the fields that needs to be captured and posted to the servlet. For this example, we need the following to be posted:
  • A File upload facility to select Excel spreadsheet.
  • A drop down box that specifies the format of uploaded workbook.(i.e. XLS / XLSX)
  • A submit button to post the data to the servlet.

HTML Form Code:


There are wide varieties of tools available in the internet to create your form. I’m not looking for a flashy form, but just a basic one to support the example. The HTML form code is given below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XLS to PDF - Servlet Example</title>
</head>
<body >
<h1><a>HTML Form to Capture user Uploaded XLS File</a></h1>
<form id="form_533088" class="appnitro" enctype="multipart/form-data" method="post" action="">
<ul >
<li id="li_1" >
<label for="element_1">Select an Excel File to Convert </label>
<input id="element_1" name="element_1" type="file"/> 
</li>
<li id="li_2" >
<label for="element_2">Excel Input Format </label>
<select class="element select medium" id="element_2" name="element_2"> 
<option value="" selected="selected"></option>
<option value="1" >XLS</option>
<option value="2" >XLSX</option>
</select>
</li>           
<li>                
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form> 
</body>
</html>


Servlet Form – Screenshot



A screenshot of the HTML form generated by the code above is provided below:


XLS to PDF - HTML Form Design
HTML Form - XLS to PDF Servlet Example



Note that I have left the action as blank intentionally. Once we have created the servlet code, we will revisit this action tag and update it back.


If you are successful until this point, you can go to the next part of the tutorial – Identifying required JAR files for conversion. Links are available 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:

Post a Comment