📄 pdfcouponservlet.java
字号:
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;/** Simple PDF-based Coupon Printer Servlet * @author Ian Darwin * @version $Id: PDFCouponServlet.java,v 1.2 2000/06/09 02:54:12 ian Exp $ */public class PDFCouponServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 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(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -