I am using jasper plugin to generate my report. All is fine but except my pdf is opening on the current tab, when I want to open it in a new tab.
I have no idea how to do it. Can anybody please help me on this please?
I am using "i-report" to design my pdf. Here is my code below :
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');
}
}
This is going to be handled by the link you use to generate the report. Typically adding a target of _blank will do the trick. For example:
This will open the link in a new tab.
If you are using a form adding target to the form will submit the form to a new tab. For example:
or
You could even do so with javascript
window.open
if you needed, but I will leave that example out of this answer as it's well documented elsewhere.