Steps Of How To Write Data Into PDF Using Servlet


Here, we're going to see how we are able to write information into PDF using servlet technology. We are clearly writing a little information about the use of servlet and it's going to get displayed withinside the PDF.

To create such an application, you want to have the spdf.jar file. If you download this instance, you'll get the instance with a jar file.

Example to write down statistics into PDF the use of servlet

Let's see the easy instance of writing statistics into PDF using the use of servlet. In this instance, we've cited the content material kind application/pdf that has to be unique to show statistics withinside the PDF format.


package com.javatpoint;  
import java.io.*;  
import java.util.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  
import com.darwinsys.spdf.PDF;  
import com.darwinsys.spdf.Page;  
import com.darwinsys.spdf.Text;  
import com.darwinsys.spdf.MoveTo;  
public class ServletPDF extends HttpServlet {  
public void doGet(HttpServletRequest request,  
        HttpServletResponse response) throws IOException {  
PrintWriter out = response.getWriter();  
response.setHeader("Content-disposition","inline; filename='javatpoint.pdf'");  
PDF p = new PDF(out);  
Page p1 = new Page(p);  
p1.add(new MoveTo(p, 200, 700));  
p1.add(new Text(p, "www.javatpoint.com"));  
p1.add(new Text(p, "by Sonoo Jaiswal"));  
p.setAuthor("Ian F. Darwin");  

download this example (developed using Myeclipse IDE)

download this example (developed using Eclipse IDE)

download this example (developed using Netbeans IDE)