title: Grails Rendering plugin save to file
body: <p>I'm trying to use the rendering plugin to save a generated pdf to a file when a controller action to generate a PDF is shown. I'm following the instructions per: <a href="http://gpc.github.com/grails-rendering/docs/manual/index.html" rel="nofollow">http://gpc.github.com/grails-rendering/docs/manual/index.html</a></p>
  
  <pre><code>def pdf = {
          def project = Project.get(params.id)
          def numGoodMilestones = queryService.getGoodShapeMilestonesCount(project)
          def totalMilestones = project.milestones.size()
          def updateHistory = queryService.getReadableHistory(project)
          def summaryName = "${project.name.replace(" ","_")}_summary_${String.format('%tF', new Date()).replace(" ","_")}"
          if(!project)
          {
              flash.message = g.message(code:'default.not.found.message',
                  args:[message(code:'project.label',default:'Project'),params.id])
              redirect(uri:'/')
          }
          // see if a summary has been generated with this data and attached to the
          // project. If not, do it.
          def existingAttachedSummary = ProjectDocument.findByName(summaryName)
          if(!existingAttachedSummary)
          {
              //make the file
              def savedSummary = new File(summaryName).withOutputStream { outputStream -&gt;
                  pdfRenderingService.render( controller:this,
                  template: "projectDetail",
                  model:[project:project,
                        numGoodMilestones:numGoodMilestones,
                        totalMilestones:totalMilestones,
                        updateHistory: updateHistory])
              }
              def projectDocument = new ProjectDocument(name:summaryName,
                                    description:"Project summary automatically generated on ${new Date()}}",
                                    fileData:savedSummary,
                                    owner: springSecurityService.currentUser,
                                    project:project
                                )
              if(projectDocument.validate())
              {
                  projectDocument.save(flush:true)
                  flash.message="I saved a document, yo. ${projectDocument}."
              }
              else
              {
                  flash.message="Errors, yo. ${projectDocument.errors.allErrors.each{ it }}."
              }
          }
          else
          {
              flash.message = "project summary already attached to project"
          }
  
          renderPdf(template: "projectDetail",
          model:[project:project, numGoodMilestones:numGoodMilestones, totalMilestones:totalMilestones, updateHistory: updateHistory],
          filename: "${summaryName}.pdf")
      }
  </code></pre>
  
  <p>The renderPdf() method works fine, as the output in my browser is what is expected.  But when I go look at the created ProjectDocument, I see a blank PDF file. I'm trying to save to a file in the exact same way described by the rendering documentation. What am I doing wrong?</p>