@Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      String templateClass = request.getParameter(AplosAppConstants.TEMPLATE_CLASS);
      if (templateClass == null || templateClass.equals("")) {
        return;
      }

      ServletContext servletContext = request.getSession().getServletContext();
      AplosContextListener aplosContextListener =
          (AplosContextListener) servletContext.getAttribute(AplosScopedBindings.CONTEXT_LISTENER);

      String processedTemplateClass;
      if (PageBindingPhaseListener.getPrintTemplateOverrideMap().containsKey(templateClass)) {
        processedTemplateClass =
            PageBindingPhaseListener.getPrintTemplateOverrideMap().get(templateClass);
      } else {
        processedTemplateClass = templateClass;
      }
      PrintTemplate printTemplate =
          (PrintTemplate) Class.forName(processedTemplateClass).newInstance();
      boolean createPdf = false;
      boolean createSizedPdf = false;
      if (request.getParameter(AplosAppConstants.CREATE_PDF) != null
          && request.getParameter(AplosAppConstants.CREATE_PDF).equals("true")) {
        createPdf = true;
      }
      if (request.getParameter(AplosAppConstants.CREATE_SIZED_PDF) != null
          && request.getParameter(AplosAppConstants.CREATE_SIZED_PDF).equals("true")) {
        createSizedPdf = true;
      }

      response.setHeader("Content-Disposition", "inline;");
      StringInputStream input = null;
      BufferedOutputStream output = null;

      try {
        printTemplate.initialise(response, request);
        String templateOutput = printTemplate.getTemplateContent();

        if (!createSizedPdf) {
          output = new BufferedOutputStream(response.getOutputStream());
          if (createPdf) {
            ITextRenderer renderer = new ITextRenderer();
            ApplicationUtil.getAplosContextListener().addFonts(renderer);
            renderer.setDocumentFromString(templateOutput);
            renderer.layout();
            renderer.createPDF(output, true);
            response.setContentType("application/pdf");
          } else {

            input = new StringInputStream(templateOutput);
            byte[] buffer = new byte[8192];
            int length;
            while ((length = input.read(buffer)) > 0) {
              output.write(buffer, 0, length);
            }
          }
        }
      } catch (Exception e) {
        AplosContextListener.getAplosContextListener().handleError(e);
        input =
            new StringInputStream(
                "There was an error trying to create this report, please contact system support");
        byte[] buffer = new byte[8192];
        int length;
        while ((length = input.read(buffer)) > 0) {
          output.write(buffer, 0, length);
        }
      } finally {
        if (output != null) {
          try {
            output.close();
          } catch (IOException logOrIgnore) {
          }
        }
        if (input != null) {
          try {
            input.close();
          } catch (IOException logOrIgnore) {
          }
        }
      }
    } catch (ClassNotFoundException cnfex) {
      AplosContextListener.getAplosContextListener().handleError(cnfex);
    } catch (IllegalAccessException iaex) {
      AplosContextListener.getAplosContextListener().handleError(iaex);
    } catch (InstantiationException iex) {
      AplosContextListener.getAplosContextListener().handleError(iex);
    }
  }