Optimization for Annotation preview loading time

Hi,

I want to inform you that annotation preview takes more loading time.So is there any optimization way to prevent more loading time ? plz suggest me.

Hello,


Thank you for the question. Yes, you can speed it up. To achieve it please do next:
1. Use .PreloadPageCount(1) in the Annotation widget
2. Use cache pre-generating with such code example:
string url = string.Empty;
HttpRequest request = 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.GenerateImages(_filePath, null, null, 100);

Thank you.

Thnx pavel for quick response.
I am using mentioned code in my controller load action but it throws an exception at time of preview as 'The Document can not be loaded '. Here is my code
Please go through it and suggest me any solution ASAP.
public ActionResult Index(int fileId, string userName)
{
try
{
DocumentCache cache = new DocumentCache(Server.MapPath("~/GroupDocs.Annotation.for.NET.lic"), Server.MapPath("~/App_Data/temp"));
cache.RemoveOldEntries(new TimeSpan(0, 5, 0), @“c:\GDViewerTmp\cache_clean_log.txt”);

if (!String.IsNullOrEmpty(userName))
{
SessionFacade.CurrentUserName = userName;

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(userName, true, 1439200);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
}
else
{
SessionFacade.CurrentUserName = “”;

var cookie = new HttpCookie(FormsAuthentication.FormsCookieName) { Expires = DateTime.UtcNow.AddDays(-1) };
Response.Cookies.Add(cookie);
Session.Abandon();
}

System.Web.Security.Membership.ValidateUser(userName, null);



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;
Session[“FileName”] = fileName;
Session[“FileId”] = fileId;
string url = string.Empty;
url = HttpContext.Request.Url.AbsoluteUri;
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;
Groupdocs.Web.UI.DocumentCache cacheDocument = new Groupdocs.Web.UI.DocumentCache(null, Server.MapPath("~/App_Data"),
Server.MapPath("~/App_Data/temp"));
cacheDocument.GenerateImages(ms, ViewBag._File, “pdf”, false, null, null, null, null);

}
}
catch (Exception ex)
{
}
return View();
}

Hello,


Thank you for the code example. Could you please also share with us the code of the web page where you have the Annotation widget.

Also we need to know which class is used for the “document” object.

Thank you.

@(Html.Groupdocs()
.Annotation()
.Stream((Stream)ViewBag._Stream, ViewBag._File)
.ElementId(“annotation-widget”)
.FilePath(“Quick_Start_Guide_To_Using_GroupDocs.pdf”)
.ShowZoom(true)
.ShowPaging(true)
.ShowThumbnails(true)
.OpenThumbnails(false)
//.Zoom(75)
.PreloadPageCount(1)
.EnableRightClickMenu(false)
.ShowFileExplorer(false)
.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)
.HighlightColor(0xFFFF00)
.TextFieldBackgroundColor(0xf0f0f0)
.MinimumImageWidth(100))



Hello,


Thank you for the code. From the code I can see that you use .Stream and .FilePath in same time. You should use only one option .Stream or .FilePath. Remove one of them

Thank you.

Hii,

I am using .Stream remove filePath but still it takes 20 sec to preview a file which is enough time so can you plz suggest me how can i reduce this loading time.

Hello,


Thank you for coming back. The loading time depends also from the server hardware (server performance) and also from the file size which you open. All what we can suggest you to speed up the loading was described in the previous posts. Also you can try to set .PreloadPageCount(2).

Thank you.

ok Thnx