FileDocCategorySizeDatePackage
PDFCouponServlet.javaAPI DocExample1366Thu Jun 08 23:54:12 BST 2000None

PDFCouponServlet

public class PDFCouponServlet extends HttpServlet
Simple PDF-based Coupon Printer Servlet
author
Ian Darwin
version
$Id: PDFCouponServlet.java,v 1.2 2000/06/09 02:54:12 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


		PrintWriter out = response.getWriter();
		response.setContentType("application/pdf");

		// Tell browser to try to display inline, but if not,
		// to save under the given filename.
		response.setHeader("Content-disposition",
			"inline; filename=\"MyCoupon.pdf\"");

		PDF p = new PDF(out);
		Page p1 = new Page(p);
		p1.add(new MoveTo(p, 100, 600));
		p1.add(new Text(p, 
			"This coupon good for one free coffee in the student lounge."));
		String name = request.getParameter("name");
		if (name == null)
			name = "unknown user";
		p1.add(new Text(p,
			"Printed for the exclusive use of " + name));
		p1.add(new Text(p,
			"by Ian Darwin's PDFCoupon Servlet and DarwinSys SPDF software"));
		p1.add(new Text(p, "at " + new Date().toString()));
		p.add(p1);
		p.setAuthor("Ian F. Darwin");

		// Write the PDF file page
		p.writePDF();