Reputation: 1
I created a word document that is in local drive and it should be opened in browser using grails gsp page.
What are the options for creating whether to create a link or by using script. Thanks in advance for helping.
Upvotes: 0
Views: 106
Reputation: 7713
to be Opened or Downloaded there are lots of options
is to use File Viewer Grails plugin Grails File Plugin
Just to provide the link in your .gsp
file as below and make a download
or view option/open
option when u press the link of that document using the following code.
in a table list show the link fetched from data base or some other source
<table>
<thread>
<tr>
<g:sortableColumn property="filename" title="Filename" />
<g:sortableColumn property="upload" title="Upload Date" />
</tr>
</thread>
<tbody>
<g:each in="${documentInstanceList}" status="i"
var="documentInstance">
<tr class="${(i%2)==0?'even':'odd'}">
<td><g:link action="download" id="${documentInstance.id}">
${documentInstance.filename}
</g:link></td>
<td><g:formatDate date="${documentInstance.uploadDate}" /></td>
</g:each>
</tbody>
</table>
def download(long id) {
Document documentInstance = Document.get(id)
if (documentInstance == null) {
flash.message = "Document not found."
redirect(action:'list')
}
else {
response.setContentType("APPLICATION/OCTET-STREAM")
response.setHeader("Content-Disposition","Attachment;Filename=\"${documentInstance.filename}\"")
def file = new File(documentInstance.fullpath)
def fileInputStream = new FileInputStream(file)
def outputStream = response.getOutputStream()
byte[] buffer = new byte[4096];
int len ;
while((len = fileInputStream.read(buffer))>0) {
outputStream.write(buffer,0,len);
}
outputStream.flush()
outputStream.close()
fileInputStream.close()
}
}
Just let me now anything .. . .
Upvotes: 1
Reputation: 371
I'm not aware of any plugins that allow you to directly render a word document in a browser / grails application. This used to be possible with old versions of Word & IE 7/8, but this is no longer the case.
A word document is basically an XML document with various markup telling the text how to render etc, and you could possibly look into loading this format. Someone has probably done this before so i'd suggest google-ing "word document parsing" or similar if you wish to investigate this option. On the other hand maybe it might be possible to save the word document as txt if you are only interested in the document text?
Hope that helps.
Upvotes: 0