CSV to PDF Servlet Conversion – HTML Form Design

We are covering in detail about CSV to PDF conversion in this tutorial series. In the last part, we wrote a standalone Java program that was successful in converting a CSV file to PDF. We would now like to write a servlet program, that accepts a user uploaded CSV file, and converts it to PDF in the server, and returns the PDF back to the user.

The first step in the servlet design is to prepare a HTML form that can post the CSV file data to the servlet. This form should contain the following elements:
  • A file upload button to accept CSV file.
  • A submit button to generate PDF output
You may want to make your form design more elegant by adding options like specifying separator type in the input file etc. For now, we will target to get a simple form ready to suit our purpose.

CSV to PDF Servlet – HTML Form

The HTML form code that can accept a CSV file and post it to the server is provided below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSV to PDF - Servlet Example</title>
</head>
<body >
<h1><a>HTML Form to upload CSV file for converting to PDF table</a></h1>
<form id="form_123" class="appnitro" enctype="multipart/form-data" method="post" action="">
<ul >
<li id="li_1" >
<label for="element_1">Select a CSV File to Convert </label>
<input id="element_1" name="element_1" type="file"/> 
</li>
<li>                
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form> 
</body>
</html>


It is a very simple form to suit the purpose. You can make the form look great by using any of your favourite techniques. A screenshot of the form in the browser is shown below:


CSV to PDF Servlet - HTML Form
HTML Form - CSV to PDF Servlet



We have left the “action” against the form blank intentionally. We will fill that once we are ready with the servlet code. In the next part of the series, we will discuss how to write the servlet code that creates PDF table from CSV file data. You can go to the next part by clicking on the links below:
This series: Convert CSV to PDF using Java
Keywords: Convert CSV to PDF, Java Example Program, OpenCSV, iText, Java Servlet Example
All Parts:
1. Convert CSV to PDF– Standard Java Program Example
2. CSV to PDF Servlet Conversion – HTML Form Design
3. CSV to PDF Converter – Full Java Servlet Program

No comments:

Post a Comment