Open pdf file in new window from variable path name in GSP page
Create Controller Method And Write A Connection To Download Your File.
GSP:
Write the Button And Create A link To this Controller Action In Your GSP like below.
<g:link class="btn btn-info btn-sm"
action="downloadMyFile" resource="${instance}"
target="_blank">DOWNLOAD FILE</g:link>
Controller:
// This is Used To Open PDF File.
def downloadMyFile(){
def file = new File("download/path/to/your/file")
response.setContentType("application/pdf")
response.setHeader("Content-disposition", "filename=${file.getName()}")
response.outputStream << file.newInputStream()
}
[OR]
// This is Simply Download Your File.
def downloadFile(){
def file = new File("Path/to/your/File")
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "filename=${file.getName()}")
response.outputStream << file.newInputStream()
}
Note:
resource : You can pass Instance to your download action.
target="_blank" : Open/Download File In New Tab.
action : Action name that is defined in Controller.
How to view a doc/pdf file in grails application?
Assuming that you don't just want to link to some other file on your server (if you do, Rahul's answer is perfectly fine) then you may want to consider something like this in a controller:
def retrieveFile() {
File fileToReturn = new File("${params.filePath}")
String filename = "whatever your filename is"
byteOutput = fileToReturn.readBytes()
response.setHeader("Content-disposition", "attachment; filename=\"${filename}\"");
outputStream << byteOutput
}
Then link to that (g.createLink or whatever) with the appropriate file path.
Grails: Render pdf from external location
If you're in grails 2.x, you can configure a target directory in Config.groovy
For instance
grails.datapath.userguides = "C:/Users/user1/userGuides/"
if you want to configure this depending the environment you can do like this :
development {
grails.datapath.userguides = "C:/Users/user1/userGuides/"
}
test {
grails.datapath.userguides = "C:/anotherDirectory/userGuides/"
}
production {
grails.datapath.userguides = "/var/www/${appName}/userGuides/"
}
Then define a controller to access your files, for example a DocumentsController with this action
def downloadUserGuide()
{
... // code to get your entity file that you use in your example to do
... // file.getValue()
String path = grailsApplication.config.grails.datapath.userguides
String label = ... // If you want to display another file name
render(contentType: "application/pdf", file: new File(path + file.getValue()), fileName: label)
}
Grails downloading pdf file from REST webservice endpoint
This is the adjusted code..but I am still getting the same result.
def generatePDF(){
String body = documentContents.responseEntity.body
ByteArrayOutputStream docStream = new ByteArrayOutputStream()
docStream.write(body.bytes) /* Write bytes into byte array*/
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=test.pdf")
response.setContentType("application/pdf")
response.setCharacterEncoding("UTF-8")
response.contentLength = docStream.size()
response.outputStream << docStream.toByteArray()
response.outputStream.flush()
response.outputStream.close()
}
Indicating in groovy to use the value of textfield named 'A ' at a different position int the same gsp
I used submitButton inside form tag.This is because the data in a text field will only be passed to the server if you submit a surrounding form (unless you use Javascript),and also as Igor Artamonov said link tag generates the link on server side,before user enters value into the text field.
Call controller in Ajax to download a file in Grails
You do not required the Ajax to download a file.
You can simply use window.location
to download your file.
Example:
$("#exportAllSelectedData").click(function() {
window.location="<g:createLink controller="mycontroller" action="exportPreferences" />"
});
If you try with Ajax, you will get(render) file text
Example:
$("#exportAllSelectedData").click(function() {
$.ajax({
type: "GET",
url: "<g:createLink controller="demo" action="exportPreferences" />",
success: function (data) {
console.log(data);
}
});
});
Hope this will helps you.
How can i do a division operation in gsp page.
Try this:
${(odimatches.count / totalmatches.count)}
show custom name in printerqueue with ghostscript
the problem was fixed by displaying the commandline like so: var gsArguments = string.Format("-ghostscript \"{0}\"{1}{2}{3} -noquery -dPDFFitPage -printer \"{4}\" \"{5}\" \"{6}\"",
GhostScript.GetExecutablePath(),
colorSetting,
duplexSetting,
copiesSetting,
_printerRepository.Find(x => x.FirstOrDefault(y => y.Id == printJob.Printer)).PrinterName,
printJob.SourceXml,
outputfilename);
all the variables represent specific settings and in contrary of what the documantion on ghostscript says that one should use /Usersettings and then /Documentname i just put the variable inline with the rest and it displays the name set to display in the printerqueue
if i misunterstood the documentation feel free to correct me, i'm posting this answer to help anyone with the same problem as i did in the future.
Related Topics
Svg Fill Animation for The Given Path
Pseudo Elements Breaking Justify-Content: Space-Between in Flexbox Layout
Web Link to Specific Whatsapp Contact
Disable Opacity on Child Element When Parent Element Has Opacity
How to Include Glyphicons in Bootstrap 3
Making Part of a Div Transparent
100% Width Table Overflowing Div Container
Wrapping Two Columns of Text Around an Image/Shape from Both Sides HTML CSS
Emoji Rendered in Chrome Have Different Widths Than in Other Browsers
Cascading Style Sheets Use "Id" or "Class"
Pure CSS 3 Image Slider - Without JavaScript or Radio Inputs
Keep Padding from Making The Element Bigger
To "User-Scalable=No" or Not to "User-Scalable=No"
Delete HTML Tags in Sed or Similar
Angular 2 Use a "Template" for Ng-Content to Use Inside Component Loop