Example to write data into PDF using servlet
Let's see the simple example of writing data into PDF using servlet. In this example, we have mentioned the content type application/pdf that must be specified to display data in 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='rajvishwakarma15@blogspot.pdf'");
- PDF p = new PDF(out);
- Page p1 = new Page(p);
- p1.add(new MoveTo(p, 200, 700));
- p1.add(new Text(p, "rajvishwakarma15@blogspot.com"));
- p1.add(new Text(p, "by Raj Vishwakarma"));
- p.add(p1);
- p.setAuthor("Ian ");
- p.writePDF();
- }
- }
download this example (developed using Myeclipse IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
Ref. javatpoint.com
No comments:
Post a Comment