Reduce Annotation Preview Loading time

Hi,


i am previewing a file having file size 2 MB for previewing this file it will take min 5-7 minutes.But i want reduce this time within some seconds.Below i will describe my code which was provided by you .Plz go through it and let me inform where i am doing fault which was not affect any changes in previewing time rather provides an error at time of previewing as 'The Document cannot be loaded '. I am also attached file which takes time.Plz test using that file.

Code Inside Controller :
public ActionResult Index(int fileId, string userName)
{
string url = string.Empty;
HttpRequest request = System.Web.HttpContext.Current.Request;
url = “http://” + request[“HTTP_HOST”] + “/”;
Groupdocs.Web.UI.DocumentCache cacheDocument = new Groupdocs.Web.UI.DocumentCache(null, Server.MapPath("~/App_Data"),
Server.MapPath("~/App_Data/temp"));
cacheDocument.RemoveOldEntries(new TimeSpan(0, 5, 0), @“c:\GDViewerTmp\cache_clean_log.txt”);

Session[“DocumentId”] = null;
Session[“UserName”] = null;
Session[“FileName”] = null;
byte[] fileBytes = document.GetFileFromDB(fileId);
int documentId = document.GetDocumentId(fileId);
string fileName = document.GetFileName(fileId);
Session[“DocumentId”] = documentId;
Session[“UserName”] = userName;
SessionFacade.CurrentUserName = userName;
Session[“FileName”] = fileName;
Session[“FileId”] = fileId;
if (fileBytes != null)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(fileBytes);
ms.Position = 0;//note this line!!!
this.ByteStream = new System.IO.MemoryStream(fileBytes);
ViewBag._Stream = ms;
ViewBag.File = documentId+""+fileName;
cacheDocument.GenerateImages(ms, ViewBag._File, “.pdf”);


}
return View();
}

View : -

@(Html.Groupdocs()
.Annotation()
.Stream((Stream)ViewBag._Stream, ViewBag._File)
.ElementId(“annotation-widget”)
.AccessRights(Groupdocs.Common.AnnotationReviewerRights.CanAnnotate)
.ShowZoom(true)
.ShowPaging(true)
.ShowPrint(true)
.ShowThumbnails(true)
.OpenThumbnails(false)
.PreloadPageCount(1)
.EnableRightClickMenu(false)
.ShowFileExplorer(true)
.Tools(Groupdocs.Web.Annotation.AnnotationTools.All)
.ShowHeader(true)
.EnableTextSelection(true)
.StrikeoutMode(Groupdocs.Common.StrikeoutToolMode.Remove)
.ScrollOnFocus(true)
.ClickableAnnotations(true)
.ConnectorPos(Groupdocs.Web.Annotation.ConnectorPosition.Bottom)
.AreaToolOptions(new Groupdocs.Web.Annotation.DrawingOptions { PenWidth = 1, DashStyle = Groupdocs.Common.DashStyle.Solid, PenColor = 0xFF0000,BrushColor=16776960 })
.PolylineToolOptions(new Groupdocs.Web.Annotation.DrawingOptions { PenWidth = 1, DashStyle = Groupdocs.Common.DashStyle.Dash, PenColor = 0xFF0000 })
.ArrowToolOptions(new Groupdocs.Web.Annotation.DrawingOptions { PenWidth = 1, DashStyle = Groupdocs.Common.DashStyle.Solid, PenColor = 0xFF0000 })
.DisconnectUncommented(true)
.ShowToolbar(true)
.HighlightColor(0xFFFF00)
.TextFieldBackgroundColor(0xf0f0f0)
.MinimumImageWidth(100))




Hello,


Thank you for the question. From your code we can see next:
1. In the DocumentCache object you use such path - Server.MapPath("~/App_Data")
It means that the document cache will be created in this folder.
2. Then you delete old cache - cacheDocument.RemoveOldEntries(new TimeSpan(0, 5, 0), @“c:\GDViewerTmp\cache_clean_log.txt”);
From this code we can assume that you use “c:\GDViewerTmp” as a root storage in the Annotation initialization method.

Please change your code in such way - For the DocumentCach object use the same folder path which you use as a root storage in the Groupdocs.Web.Annotation.WidgetFactory.Initialize(); method. and then use only this path for all manipulations with the files which you will use in the Annotation.

Also removing of the old cache should be done from time to time - don’t use it for each time when page load because it takes time for processing too.

Best regards.

Thnx for suggesting me to make changes in code .But why did it gives exception at time of previewing that ‘The Document cannot be loaded’? plz suggest me any solution for this error.

One more thing i noticed that when i am previewing a compressed file then loading time of un compressed file takes less time as compared to compressed file. So is there any issue behind this ??

Hello,


If I understand you correct you tried to use in the Annotation compressed file i.e. rar or zip file?

If so unfortunately our libraries doesn’t supports such files. Since that you get such error.

Best regards.

Hi Pavel,


I think you are not getting my problem .Previously annotation preview was working fine after writing code for reducing load time ‘Document cannot be loaded’ error comes at time of previewing any file.I already post the code .Please go through prev forum post and let me know where i m doing fault.

Hi Pavel,


The file is not a rar or zip file. it is just a normal file but the size of file is less since the images inside the file are compressed(resolution is less). I am attaching both the files please test and do needful.

Hello,


We have checked loading time with your files and it takes less then a 3 seconds for initial (first time) view .

Please check performance in this example project and compare it’s code with your project code.

Thank you.

Hi,


I am not asking about the page load or initial view. I am asking about the pdf file loading. The less sized(MyFile2.pdf) file thumb nails and file pages takes more time to load but the larger(myfile.pdf) one takes less time. Please try to open both the files and compare time. Might be there is some configuration or setting issue which we are unable to find out or is there any limitation for specific files. if it is specific then suggest the file properties for which the loading time is minimum.

Also I request you to please provide a .Net MVC example.

Hello,


Thank you for coming back. Sure we will prepare MVC project example which will show how to work with the cache properly.

Please be patient it will be ready soon.

Hello,


Sorry for the delay. Please download example here

Best regards.