title: Emailing a PDF from AbstractPdfView in Java
body: <p>I use the AbstractPdfView class to generate a pdf and download in the browser but I also need to email it. I know the solution is very obvious, but i've been stuck on this for a day now and cannot get see it. Here what i have so far:</p>
  
  <pre><code>@GetMapping()
  public PdfView generate(Model model, @RequestParam int event) {
  
    model.addAttribute("event", eventService.getEventById(event));
  
    return new PdfView();
  
  
  }
  </code></pre>
  
  <p>That is the PdfView class:</p>
  
  <pre><code>public class PdfView extends AbstractPdfView {
  
     @Override
     protected void buildPdfDocument(Map&lt;String, Object&gt; model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception {
  
          //add the iformation for the pdf
          document.add(getInvoiceInfo());
  
     }
  }
  </code></pre>
  
  <p>And that is the AbstractPdfView class:</p>
  
  <pre><code>public abstract class AbstractPdfView extends AbstractView {
  
     public AbstractPdfView() {
        setContentType("application/pdf");
     }
  
     @Override
     protected boolean generatesDownloadContent() {
        return true;
     }
  
     @Override
     protected final void renderMergedOutputModel(Map&lt;String, Object&gt; model, HttpServletRequest request, HttpServletResponse response) throws Exception {
  
    ByteArrayOutputStream out = createTemporaryOutputStream();
  
    Document document = new Document(PageSize.A4.rotate(), 35, 35, 50, 36);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    prepareWriter(model, writer, request);
    buildPdfMetadata(model, document, request);
  
    document.open();
    buildPdfDocument(model, document, writer, request, response);
    document.close();
  
      //i know i has to happen before this bit here but not sure how
     writeToResponse(response, out);
  
  }
  
     protected void prepareWriter(Map&lt;String, Object&gt; model, PdfWriter writer, HttpServletRequest request) throws DocumentException {
        writer.setViewerPreferences(getViewerPreferences());
     }
  
     protected int getViewerPreferences() {
        return PdfWriter.ALLOW_PRINTING | PdfWriter.PageLayoutSinglePage;
     }
  
  
     protected void buildPdfMetadata(Map&lt;String, Object&gt; model, Document document, HttpServletRequest request) {
     }
  
     protected abstract void buildPdfDocument(Map&lt;String, Object&gt; model, Document document, PdfWriter writer,
                                              HttpServletRequest request, HttpServletResponse response) throws Exception;
  }
  </code></pre>
  
  <p>Any help is welcomed! Thank you guys.</p>