我试图使用渲染插件将生成的PDF保存到文件,当控制器操作生成PDF时显示。我下面按照指示:http://gpc.github.com/grails-rendering/docs/manual/index.htmlGrails渲染插件保存到文件
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 ->
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")
}
的renderPdf()方法的正常工作,在我的浏览器输出的期望是什么。但是当我查看创建的ProjectDocument时,我看到一个空白的PDF文件。我试图用渲染文档中描述的完全相同的方式保存到文件中。我究竟做错了什么?
你有没有得到这个工作? – 2012-07-04 17:41:37