How to render document from stream in HTML based rendering

Hi


I am using Viewer for .Net v3.3
I want to use rendering data from stream object but I am not able to do that as
current implementation require file name and File path to progress further.

Please share a example aspx page or source to clarify how to use stream for document rendering and displaying on front end.

Thanks
Puneet Rajak

Hi Puneet,


Thanks for posting your query.

Loading documents from stream is already implemented in our sample front end applications. The working is slightly different from the scenario you mentioned. The JavaScript receives file name and a web request is posted to get stream of the file. The stream is then saved as file in Storage folder. Please find the attached screenshot of the code which fulfills this purpose in WebForms Front End.

You can change/modify this code according to your requirements. If you have any further questions, please let us know.


Warm Regards

Hi


We are able to use rendering document via stream method,
though we found that when we use stream via below code,
if (Utils.IsValidUrl(request.Path))
request.Path = DownloadToStorage(request.Path);
else if (((Dictionary<string, Stream>)HttpContext.Current.Session[“DocumentStream”]).ContainsKey(request.Path))
request.Path = SaveStreamToStorage(request.Path);

SaveStreamToStorage method actually creating a local file in the storage path and consume that file to create caching.

It is an extra burden for us to handle that local file because multiple use would going to use large amount of document, this would create bulk of local files and consume unnecessary space at server.

Please response to below 2 concern.
1. How could we directly cache a document without creating local files. this would be preferred solution for us.
2. Current implementation create local files before cache, so does cache removal method would take care of deleting these local files too.

Thanks
Puneet Rajak



The issues you have found earlier (filed as VIEWERNET-701) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by groupdocs.notifier.

Hi Puneet,


I am writing inline answers of your questions.

1. How could we directly cache a document without creating local files. this would be preferred solution for us.

GroupDocs.Viewer for .NET also provides overloaded function which work with the stream objects. Please try one the following functions in your code and share your experience.

  • ViewerHtmlHandler.GetPages(Stream, HtmlOptions)
  • ViewerHtmlHandler.GetPages(Stream)


2. Current implementation create local files before cache, so does cache removal method would take care of deleting these local files too.

Absolutely. ClearCache() function will clear all the files that are created in cache directory. Please note that if you have not set a cache path in configurations then temp folder will be used as default cache directory and ClearCache() with remove files in temp folder.

If you have any further questions, please let us know.

Warm Regards


Hi Usman,


We tried using GetPages() method with both parameter, though it is throwing exception of ‘GroupDocs.Foundation.Exception.GroupDocsException’.

Attached is the screenshot of that error.

could you please use the Default.aspx.cs page of sample solution provided from Groupdocs and pin down all the changes, code example which required to execute this method.

currently the error code is below.
private static List GetHtmlPages(string filePath, HtmlOptions htmlOptions, out List cssList)
{
var htmlHandler = (ViewerHtmlHandler)HttpContext.Current.Session[“htmlHandler”];
var htmlPages = htmlHandler.GetPages(_streams[filePath], htmlOptions); //Exception here
//Some more code.
}

The _stream[filePath] is giving correct stream as I have already created a local copy from that stream without any error.

Beside from this, I can see from sample example that you are using below code
public static ViewDocumentResponse ViewDocument(ViewDocumentParameters request)
{
if (Utils.IsValidUrl(request.Path))
request.Path = DownloadToStorage(request.Path);
else if (_streams.ContainsKey(request.Path))
request.Path = SaveStreamToStorage(request.Path); // Create Local copy: Not Required
//Some code here
}

if this code is already creating local file they how can we avoid this or what code should we use to replace above code.

2. I have checked the cache clean method, it does only delete files from the Temp folder inside Cache. It does not delete those local files which is created using SaveStreamToStorage()
Could you please suggest how could we delete that local file from your CacheClean Method.

Please consider 1 point as desirable solution for us(not to create local file at all).

Thanks
Puneet Rajak



Hi Puneet,


Thanks for reporting your issue.

We have successfully reproduced the exception which you are getting in case of Stream object. I have logged the issue for further investigation. Once we have any fix/update, we will notify you here.

For point 2 in your post, please share the ViewerConfig settings with us so that we can get more closer to your issue. After seeing the config settings we shall be able to point out the problem.

We shall be waiting for your response.

Warm Regards

Hi Usman


Thanks for raising this with your team.
Please also share some expected date for the fixes as we need to update our customer on this.

for the point 2, on taking example of your sample solution
below is the viewer config setting.
ViewerConfig viewerConfig = new ViewerConfig
{
StoragePath = @“D:\v3.3\WebForm_Front_End\GroupDocs.Viewer.WebForm.FrontEnd\App_Data”,
TempPath = @“D:\v3.3\WebForm_Front_End\GroupDocs.Viewer.WebForm.FrontEnd\App_Data\temp”,
UseCache = true,
CachePath= @“D:\v3.3\WebForm_Front_End\GroupDocs.Viewer.WebForm.FrontEnd\Cache”
};

the file is deleting from CachePath folder not from storage, where my local files are stored.
Thanks
Puneet Rajak

Hi Puneet,


Thanks for sharing details.

Currently, we don’t have any expected date of the fix. Once we do have any information, we will surely notify you.

Regarding config settings, please note that ClearCache() only cleans files/folders in cache directory not in storage directory. You can handle this situation by writing some custom code to remove file from storage directory when it is completely rendered. Please try this and share your experience.

Warm Regards


Hi Usman,

Thanks for the response.


Could you please provide any update on the issue raised in 13174
we are expecting that using
  • ViewerHtmlHandler.GetPages(Stream, HtmlOptions)
  • ViewerHtmlHandler.GetPages(Stream)

would resolve our problem of creating local files for caching.
we actually do not require creating local files as this would going to consume large space when traffic is high on Viewer.

Thanks
Puneet Rajak

Hi Puneet.


The investigation of this issue has been started and once we have any updates, we will surely notify you. We appreciate your patience in this regards.

Please stay tuned.

Warm Regards

Hi Puneet,


Your issue related to stream object has been resolved. The fix will be available in next version, v3.4.0, which is planned to be released in second half of June.

Warm Regards

Hi Umar,


As we reached 2nd half of June, could it be possible for you to deliver next version of viewer with fixes or share some specific date of v3.4.0 release.

Thanks
Puneet Rajak

Hi Puneet,


Yes, we have reached 2nd half of June and I am pleased to inform you that GroupDocs.Viewer for .NET 3.4.0 is going to be released very soon. You will have to wait a little more in this regards. We appreciate your patience and cooperation.


Warm Regards