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();