Вы можете использовать iText - зрелую библиотеку с открытым исходным кодом для создания PDF-документов. Следующий пример основан на Struts 1, но может вам помочь:
public class PDF extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World"));
//
// add your data here ...
//
document.close();
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
} catch (Exception e2) {
System.out.println("Error in " + getClass().getName() + "\n" + e2);
}
return null;
}
}