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.
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>
inside you DocumentController under download action put this code to make the file available to be downloaded or viewed based on the browser option
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 .. . .
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.
Related
I have tried for more than two hours and I can not find an answer to this problem. I have this part of the code in a view strongly typed in MVC:
<td>
#foreach (var TitleBook in Directory.GetFiles(Server.MapPath("~/App_Data/Images"), "*.jpg"))
{
var fileName = Path.GetFileName(TitleBook);
if (Convert.ToInt32(fileName.Substring(0,3)) == item.IdBook)
{
<img src="#TitleBook" alt="Alternate Text" height="100" width="100">
}
}
</td>
The name of the image file is created so the three first characters in the filename are numbers.
When I run the code, I get the alternate message for the image in the hmtl view. However, the path to this image is well read and I know it because I can obtain it by doing inspect in the browser and calling only the src part of in another window which shows the image as expected (sorry for my English). The css is handled by the version of boostrap installed in VS2017.
Could someone point to my error here?
Your titleBook is a full physical path. But <img> wants an URL.
Untested:
<img src="~/App_Data/Images/#fileName" alt="Alternate Text" height="100" width="100">
BTW: with Directory.GetFiles(..., $"{item.IdBook:D3}*.jpg")) you wouldn't need the foreach loop.
I have problem with TCPDF to show on PDF page my UTF-8 data. Here is part of my code :
TCPDF work fine, but when create Pdf I get ?a?anska insted Čačanska.
I try with "SET NAMES 'utf8'" ,but no result.. If I remove utf8_encode, get blank page.
I try to use this answer, but no help:
Why cant I use č,ć,đ charters in TCPDF table?
and my old question:
TCPDF don't show č,ć,ž,š,đ from mysql only blank page
Font:
$pdf->SetFont('freeserif', '', 14, '', true);
Create Pdf:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
Part od code :
$id =$_POST['ajde']; // get data from jqgrid
$result = mysqli_query($con,"SELECT * FROM kuca where id=$id ");
while($row = mysqli_fetch_array($result))
{
$u= $row['adresa'];
$html = '
<table width="540" height="339" border="1" align="center" cellpadding="2" class="table table-hover" >
<tr>
<td><div align="left">Adresa:</div></td>
<td style="font-family:freesans" ">' . $u. '</td>
</tr>
</table>
$pdf->writeHTML(utf8_encode($html), true, 0, true, 0);
Tnx,
Pavle
I'm not sure if you still need to know this, but I already explained it in one of my answers, but you need to encode you content to utf-8 again (and utf-8 already encoded, remains utf-8 in PHP) and convert it to HTML_ENTITIES. I may explained it a bit weird, so people can correct me on that : )
In short:
$your_new_content = mb_convert_encoding(utf8_encode($your_content), 'HTML-ENTITIES', 'UTF-8');
Oh, a reminder that this fix will mess up your regular echoes, but it will turn out well in TCPDF. This fix can be used on various things, so I hope this helps.
Hello stackoverflow people
hope you can help me with maybe a simple question, but couldn't find a solution elsewhere and I have just been working with umbraco for a week now and have never used the mvc part before so all is new for me.
So the big problem is how I make a macro to show these images I choose from the multiple media picker the macro should just end with showing.
<img src="img1.gif" height="50" width="50">
<img src="img2.gif" height="50" width="50">
And so on depending on how many images there is. (the size is just an exempel)
I tryed somthing like this
#var selectedMedia3 = #Library.MediaById(Model.mainImage);
<img src="#selectedMedia3.umbracoFile" width="#selectedMedia3.umbracoWidth" height="#selectedMedia3.umbracoHeight" alt="#selectedMedia3.Name"/>
}
But I dont know how to parse the id of the image to the macro.
and when I choose more than one file I need a loop, but dont know how to loop the multiple media picker data, so im a little lost by now.
Are you able to let us know what version of Umbraco you are using. Umbraco has gone through a number of fundemental changes in various version over recent years. The below code should guide you in the right direction for Umbraco 7 Multiple Image picker with the propertyAlias partnersLogos.
#if (Model.Content.HasValue("partnersLogos"))
{
var partnersImagesList = Model.Content.GetPropertyValue<string>("partnersLogos").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
var partnersImagesCollection = Umbraco.TypedMedia(partnersImagesList).Where(x => x != null);
foreach (var partnerImage in partnersImagesCollection)
{
<img src="#partnerImage.Url" alt="partners logo" />
}
}
If anyone makes the same mistake as me and doesn't realise that there is a difference between the now obsolete media picker and the new media picker "Umbraco.MediaPicker2" (true from at least 7.6.1) then please read the documentation on Umbraco's web site.
https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker2
#{
var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("sliders");
foreach (var item in typedMultiMediaPicker)
{
<img src="#item.Url" style="width:200px"/>
}
}
I'm not really sure if you question is how to setup MVC within umbraco or getting values from an image picker.
But if you want to start up with MVC in umbraco check this out: http://24days.in/umbraco/2013/creating-reusable-code-in-mvc-apps/
In my MVC application, user can upload various type of files (pdf, jpg, txt etc) and I want to show icon specific to each type, currently I am using one icon (pdf) for the purpose, I want, that based on the file type, associated icon should be displayed. Please guide me what kind of approach I can use for this purpose
<td>
#if (item.CalibratedBy != null){
<a href = #Url.Action("ViewCertificate", new { fileName = item.CalibrationCert }) >
<img src = "#Url.Content("~/Content/Icons/pdf.jpg")" alt = "attachment" /> </a>
}
</td>
Expose the extension type needed as a property on item (presumably being passed in through the Model)
Create an HtmlHelper extension method that will take in item.FileType and return the path to the appropriate icon file to be used. Call this in your <img> tag.
I'm using the object tag to render PDF in HTML, but I'm doing it in MVC like this:
<object data="/JDLCustomer/GetPDFData?projID=<%=ViewData["ProjectID"]%>&folder=<%=ViewData["Folder"] %>"
type="application/pdf" width="960" height="900">
</object>
and Controller/Action is
public void GetPDFData(string projID, Project_Thin.Folders folder)
{
Highmark.BLL.Models.Project proj = GetProject(projID);
List<File> ff = proj.GetFiles(folder, false);
if (ff != null && ff.Count > 0 && ff.Where(p => p.FileExtension == "pdf").Count() > 0)
{
ff = ff.Where(p => p.FileExtension == "pdf").ToList();
Response.ClearHeaders();
Highmark.BLL.PDF.JDLCustomerPDF pdfObj = new JDLCustomerPDF(ff, proj.SimpleDbID);
byte[] bArr = pdfObj.GetPDF(Response.OutputStream);
pdfObj = null;
Response.ContentType = "application/" + System.IO.Path.GetExtension("TakeOffPlans").Replace(".", "");
Response.AddHeader("Content-disposition", "attachment; filename=\"TakeOffPlans\"");
Response.BinaryWrite(bArr);
Response.Flush();
}
}
The problem is, as I'm downloading data first from server and then return the byte data, it is taking some time in downloading, so I want to show some kind of progress to show processing.
Please help me on this.
You may try the following (not tested under all browsers):
<div style="background: transparent url(progress.gif) no-repeat">
<object
data="<%= Url.Action("GetPDFData, new { projID = ViewData["ProjectID"], folder = ViewData["Folder"] }") %>"
type="application/pdf"
width="640"
height="480">
<param value="transparent" name="wmode"/>
</object>
</div>
Unfortunatly, there is no way (afaik) to interact with the Acrobat plugin and see when it's ready to display your PDF document.
There are components available that replace Acrobat and provide a proper Javascript interface.
I work for TallComponents on their PDFWebViewer.NET product which will display PDF without any plugins and works with ASP.NET MVC.
You do have some other options though. If you need the progress indicator because the PDF generation is taking longer than you would like you can poll the server for progress using AJAX calls.
On the server you would need to have some sort of progress information available that you can return as the result of the ajax call. In the browser you'd use the result to provide progress info to the user. There are several good examples available online (this blog for example). There are also other questions here on SO (for example here) with good pointers to more info.
If the generation process only takes a couple of seconds can you probably get way with showing a busy indicator. That could be as simple as showing a div in your page when you trigger the download from the server.
By the way, if I'm not mistaken you should replace the attachment keyword with inline in the Content-Disposition header. Setting that to attachment will cause the entire PDF to be downloaded before any content is displayed. If you set it to inline, Acrobat will start showing the first page as soon as it has downloaded enough data to do so.