title: Pdf template with iText and Spring MVC
body: <p>I want to create a PDF from a template (using pdf forms as shown <a href="http://ashwinrayaprolu.wordpress.com/2011/06/07/pdf-templates-using-openoffice-draw-and-itext-in-java/" rel="nofollow">here</a>) in Spring MVC and output it to the browser using <code>AbstractPdfView</code> but I don't know how to obtain a <code>Document</code> from the <code>PdfStamper</code>, or if I should use the <code>PdfWriter</code>.. any idea? Below is the code I have so far, thanks</p>
  
  <pre><code>public class RecipePdf extends AbstractPdfView {
  
  @Override
  protected void buildPdfDocument(Map&lt;String, Object&gt; model, Document document,
          PdfWriter pdfWriter, HttpServletRequest request, HttpServletResponse response)
          throws Exception {
  
      PdfReader pdfTemplate = new PdfReader ("/WEB-INF/template/recipe.pdf");
      FileOutputStream fileOutputStream = new FileOutputStream("test.pdf");
      PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);
      stamper.setFormFlattening(true);
  
      stamper.getAcroFields().setField("number", "12345");
  
      stamper.close();
      pdfTemplate.close();
  </code></pre>