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.
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.
ServletPDF.java
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.setContentType("application/pdf"); 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.add(p1); p.setAuthor("Ian F. Darwin"); p.writePDF(); } }
download this example (developed using Myeclipse IDE)