Hello Dhivya,
Hi,
This is my angularjs call and I am not able to receive the streamdefinition here.
Hello Dhivya,
Thank you for the question. In such case you need to update your code with the following:
- In the view change your AJAX call in such a way:
<div id="container"></div>
<div id="test" style="margin-bottom:20px"></div>
$(document).ready(function () {
var serviceURL = "myaction";
$.ajax({
type: "POST",
url: serviceURL,
data: docPath,
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
$("#container").append(
'<div id="test" style="width: 100%; margin-bottom: 20px; height: 900px;" runat="server"></div>' +
'</div>' + data
);
}
function errorFunc() {
alert('error');
}
});
- In the controller (assuming the action is named
Ajax()):
public ActionResult Ajax()
{
string filename = "candy.pdf";
// Obtain a stream from wherever you need. Here we get it from a file.
string path = Server.MapPath("~/testfiles/" + filename);
System.IO.Stream byteStream = new System.IO.FileStream(
path,
System.IO.FileMode.Open,
System.IO.FileAccess.Read
);
string groupdocsViewerScript = Groupdocs.Web.UI.Viewer.ClientCode()
.TargetElementSelector("`#test`")
.Stream(byteStream, filename, "pdf")
.Height(900)
.ToString();
return Content(groupdocsViewerScript, "text/plain");
}
That’s all.
In few words, you just need to follow this logic:
- From the view you make an AJAX call to an action, sending the file name in the data.
- In the action you receive the file name and obtain its stream.
- In the same action you generate the viewer code (e.g., see the example Viewer code) with this stream (adjust options as needed).
- Return the generated viewer code as a string.
- In the success function of the AJAX call, add the HTML content to the page. Note that you need two
<div>elements for the viewer: one withid="container"(the main div) and one withid="test"(where the viewer script will be injected).
Best regards.
Hi Dhivya,
Thank you for these questions.
-
In your use case using of stream is an only way to achieve your goal – to store cache in one place inside the application.
-
Full code of the widget will be:
string groupdocsViewerScript = Groupdocs.Web.UI.Viewer.ClientCode()
.TargetElementSelector("#test")
.Stream(ByteStream, filename, "pdf")
.PreloadPagesCount(1)
.Quality(100)
.ShowThumbnails(true)
.OpenThumbnails(false)
.Zoom(100)
.ZoomToFitWidth(true)
.Width(0)
.ShowFolderBrowser(false)
.SupportTextSelection(true)
.UsePdfPrinting(false)
.ShowDownloadErrorsInPopup(false)
.ShowImageWidth(false)
.EnableStandardErrorHandling(true)
.UseHtmlBasedEngine(true)
.DownloadPdfFileIfPossible(false)
.SearchForSeparateWords(false)
.ShowHeader(true)
.Height(0)
.ToString();
All other options that you have are set to default values, so you don’t need to set them here. If you need to change some other option value, you can find all options as shown in the screenshot.
Best regards.
Hi again,
Hi,
Hi,
Perfect!! Thanks a lot. Everything is working now as required.
Hi
Hi,
Hi,
Hi,
Hi,