Closed CanerKarakurt closed 3 years ago
@CanerKarakurt
Thanks for your query and sorry for late reply. We'll investigate this requirement and will get back to you soon.
@CanerKarakurt
Can you please specify the platform (.NET, Java) you're working on?
Hi @atirtahirgroupdocs working on .net
Regards
@CanerKarakurt
Using GroupDocs.Viewer for .NET API you can render a documents without downloading it. API allows you to load source document from multiple sources (e.g. Amazon S3 storage, Azure Blob, Stream) and then render them into HTML, image or PDF formats. By default GroupDocs.Viewer saves output results to the local disk but we also provide a way to save output results into a stream. Once API renders source document and returns output, you can display that output in browser. Please let us know if this information meets your requirements. We'll then provide you a solution.
when I try to put a stream in the viewer I get following failure:
Cannot convert from “System.IO.MemoryStream” to
“GroupDocs.Viewer.Common.Func
code:
attachmentStream = new MemoryStream(attachment.Content);
using (Viewer viewer = new Viewer(attachmentStream))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForExternalResources();
viewer.View(viewOptions);
}
@CanerKarakurt
Cannot convert from “System.IO.MemoryStream” to “GroupDocs.Viewer.Common.Func
”
Please have a look at the below code:
public static void Run()
{
string outputDirectory = Utils.GetOutputDirectoryPath();
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
using (Viewer viewer = new Viewer(GetFileStream))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
viewer.View(options);
}
Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}
private static Stream GetFileStream() => File.OpenRead(TestFiles.SAMPLE_DOCX);
This is how you load a document from stream and then pass it to Viewer.
I've seen this however this requires you have a file in the file system I need to avoid that and load directly from a stream.
@CanerKarakurt
From which source/stream exactly you are loading the document (e.g. FTP, URL, S3 or blob storage)? Or can you please share your use-case/requirement.
Directly from Microsoft exchange server. Use case:
User receives an email with a bunch of attachments. They then click on the attachment they want to view and view it directly in the browser without having to download it onto any machine. Think of the way outlook online works. You can view an attachment directly on the browser without having to download it.
Regards
@CanerKarakurt
Thank you for the details. Please create a thread on our forum with reference of this GitHub issue. We'll then investigate it and you'll be notified on forum.
Done, I would need an answer soon as I have a client expectation. If it is not possible then I would have to look at other products.
Regards
@CanerKarakurt We are investigating your use-case. You'll be notified as there's any update.
@CanerKarakurt
We have an update. In order make your code work, you have to pass stream factory instead of stream:
attachmentStream = new MemoryStream(attachment.Content);
using (Viewer viewer = new Viewer(() => attachmentStream))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForExternalResources();
viewer.View(viewOptions);
}
Let us know if it works for you.
I have the same problem. I am working with MVC5, I want to view document in view and I have memory stream in controller. please suggest the appropriate solution.
@RakeshPatel2692
I have the same problem. I am working with MVC5, I want to view document in view and I have memory stream in controller. please suggest the appropriate solution.
Please have a look at this thread.
Not able to download sample.zip getting below error "Sorry, this file is private. Only visible to topic owner and staff members."
@RakeshPatel2692 You can download the project here - sample.zip.
@atirtahirgroupdocs Please help me with MVC sample project . As I want to view document in MVC view. Already I have memory stream in my controller.
@RakeshPatel2692 Please download a sample project here.
It works for me. Still I want show the document in div. Don't want to use Iframe. @atirtahirgroupdocs
we are not using angular. Project UI is based on HTML+JQuery. Is there any way to show document in view.
@RakeshPatel2692
You can pass the MemoryStream
to view using ViewData
and then render the output in Razor View.
Download or clone this application.
In HomeController and Index action, change following code:
return File(outputStream, "text/html");
with this:
ViewData["PageContent"] = outputStream;
return View();
And in Index View you can show document in div:
@using System.IO
@using System.Text
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Render page on the server</h1>
<div>
@{
MemoryStream stream = (MemoryStream)ViewData["PageContent"];
string pageContent = Encoding.UTF8.GetString(stream.ToArray());
}
@Html.Raw(pageContent)
</div>
</div>
The related project can be viewed here Display documents from a MemoryStream in ASP.NET MVC/.NET Core
I have a scenario where I get an attachment from an exchange server and stream it back to the browser. I need to be able to render these files in the browser without having to download them on to the machine.