protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/pdf");
try {
// We get a resource from our web app
response.setContentType("application/pdf");
try {
Document document = new Document();
PdfWriter.getInstance(document, response.getOutputStream());
document.open();
document.add(new Paragraph("Hello World"));
document.add(new Paragraph(new Date().toString()));
Paragraph p = new Paragraph();
Chunk imdb = new Chunk("Internet Movie Database");
imdb.setAction(new PdfAction(new URL("http://localhost:8080/iTextPdf/servlet/PdfServlet1")));
p = new Paragraph(
"Click on a country, and you'll get a list of movies, containing links to the ");
p.add(imdb);
p.add(".");
document.add(p);
p = new Paragraph("This list can be found in a ");
Chunk page1 = new Chunk("separate document");
page1.setAction(PdfAction.createSubmitForm("/PdfServlet", null, 0));
p.add(page1);
p.add(".");
document.add(p);
document.add(Chunk.NEWLINE);
document.close();
} catch (DocumentException de) {
throw new IOException(de.getMessage());
}
//
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
pdf 简单连接servlet
最新推荐文章于 2024-01-17 15:21:56 发布