I have also tried the following in a controller:
// set the working directory
var workingdirectory = System.IO.Path.GetDirectoryName(fd.Path);
// convert the file to a pdf (returns bytes)
var convertedfile = new Groupdocs.Engine.Viewing.HtmlViewingService(workingdirectory).GetPdfFile(fd.FileName, 0, true);
// convert the file to end with pdf
var convertedfilename = System.IO.Path.GetFileNameWithoutExtension(fd.FileName) + “.” + “pdf”;
// set the location to copy the new temp file
var newfilepathwithname = System.IO.Path.Combine(System.IO.Path.Combine(“TempPathToFile”, convertedfilename);
// write the bytes to a file
System.IO.File.WriteAllBytes(newfilepathwithname, convertedfile);
// set the new file path and name
fd.Path = newfilepathwithname;
fd.FileName = convertedfilename;
Response.ContentType = “application/octet-stream”;
Response.AppendHeader(“Content-Disposition”, “attachment; filename=” + convertedfilename + “”);
return File(new FileStream(fd.Path, FileMode.Open), “text/plain”, convertedfilename);
And then placed javascript on the viewer page:
$(document).ready(function () {
var containerElement = $("#DocumentViewer");
containerElement.groupdocsViewer(“on”, “downloadButtonClick.groupdocs”,
function (e, zoom) {
window.location = ‘PointerToMyController’;
e.stopImmediatePropagation(); // none of this seems to work either
e.preventDefault();
e.stopPropagation();
return false;
});
});
The javascript runs, the page then hits my controller but the file that I created using the GetPdfFile method is not returned (even though when debugging it goes all the way to the return File line). It just returns the file from the Viewer. The e.preventDefault() and others dont seem to stop the click event either…