Handle the get request.
try {
out = new PrintWriter(response.getOutputStream());
int font;
pdflib p = new pdflib();
if (p.open_file("") == -1) {
warning(response,
"Couldn't create in-memory PDF file", null);
return;
}
p.set_info("Title", "Dictionary Project");
p.set_info("Author", "Ian F. Darwin, http://www.darwinsys.com/");
p.set_info("Creator", "www.darwinsys.com/dictionary");
p.begin_page(595, 842);
font = p.findfont("Helvetica", "host", 0);
p.setfont(font, 14);
// XXX for now just use one term from the Iterator
Iterator e = new TermsAccessor("terms.txt").iterator();
Term t = (Term)e.next();
p.set_text_pos(50, 700);
p.show("Term: ");
p.continue_text(t.term);
p.set_text_pos(70, 666);
p.show("Definition: ");
p.continue_text(t.definition);
p.end_page();
p.close();
byte[] data = p.get_buffer();
response.setContentType("application/pdf");
response.getOutputStream().write(data);
} catch (IOException e) {
warning(response, "pdflib IO error:", e);
return;
} catch (Exception e) {
warning(response, "pdflib error:", e);
return;
}