我正在使用jasper插件来生成我的报告。一切都很好,但我的pdf在当前选项卡上打开,当我想在新标签中打开它。
我不知道该怎么做。请有人帮帮我吗?
我正在使用“i-report”来设计我的pdf。以下是我的代码:
def index = {
println(params)
def testModel = this.getProperties().containsKey('chainModel') ?
chainModel : null
JasperReportDef report = null
if (params.containsKey('auto_print_dialog')){
report = docuJasperService.buildReportDefinition(params,
request.getLocale(), testModel)
}
else{
report = jasperService.buildReportDefinition(params,
request.getLocale(), testModel)
}
generateResponse(report)
}
def generateResponse = {reportDef ->
if (!reportDef.fileFormat.inline && !reportDef.parameters._inline) {
//response.characterEncoding = "UTF-8"
//response.setHeader("Content-disposition",
//"inline; filename=${params._name}");
response.setHeader("Content-disposition", "inline;
filename="+(reportDef.parameters._name ?: reportDef.name) +
"."+reportDef.fileFormat.extension);
response.contentType = "application/pdf"
response.outputStream << reportDef.contentStream.toByteArray()
} else {
render(text: reportDef.contentStream, contentType:
reportDef.fileFormat.mimeTyp,
encoding: reportDef.parameters.encoding ?
reportDef.parameters.encoding : 'UTF-8');
}
}
答案 0 :(得分:4)
这将由您用于生成报告的链接处理。通常添加_blank的目标就可以了。例如:
<g:link controller="myReports" action="whateverReport" target="_blank">Click for your report</g:link>
这将在新标签页中打开链接。
如果您使用表单添加表单,则会将表单提交到新选项卡。例如:
<form name="myForm" action="whateverReport" method="POST" target="_blank">
或
<g:form name="myForm" controller="myReports" action="whateverReport" target="_blank">
如果您需要,您甚至可以使用javascript window.open
进行此操作,但我会将此示例留在此答案中,因为它在其他地方有详细记录。