Free Support Forum -

DocumentCache and annotations

trying to use DocumentCache cache with annotations and am struggling a bit with it, so wondered if you perhaps help. The scenario I have in mind:

1. Get document with an HttpWebRequest (from a SharePoint site) and use the DocumentCache.GenerateImages() call to cache the response stream. This works fine and I end up with a PDF in the /temp/s/ folder and files in the cache and processing folders.

2. A separate webpage then try to load the cached document into the annotations viewer. I've tried specifying just the file name of the file in /temp/s/ (annotation viewer doesn't load anything) and the full path (/temp/s/) when calling FilePath() on WidgetFactory (annotation viewer shows error about invalid characters in the path).

So how do I get the annotations viewer to access a previously cached file (that was cached using a stream)?

In an ideal world I'd also like to be able to use different root folders for where I store the cached documents and where the annotations viewer pick them up from. The WidgetFactory.Initialize() method seems to indicate this isn't possible since the samples show it being called in Application_Start(), but have also seen SetRootStoragePath() method in the Viewer documentation that has a 'per request' param. So is there a way to use different locations per request with the annotations viewer? If so - do you have some samples that show how to do this?



Hello Pete,

Thank you for the question. Lets start from the cache - you can access directly to the cache files and view them. The idea of the DocumentCache is to allow users to create document cache before the document will be opened for view and speed up it’s processing (Annotation will open document more faster if the cache already created). Since that to achieve your goal you need to do next:
1. Save document in the folder which you set as a root storage for the Annotation.
2. Generate it’s cache by using already saved document (after saving the document please don’t use obtained from SP stream)
3. Use document name in the .FilePath - for example: you have a root storage folder called “rootStorage” and you have saved obtained document as a “testfile.docx”. Now you have generated it’s cache (in the rootStorage folder the temp folder created with all document cache). To open the document you simply should use .FilePath(“testfile.docx”).

As for different root storages - sorry but currently this feature doesn’t supported. We works on the brand new Annotation and we will investigate this feature. If it will be possible we will add it to our roadmap.

Thank you.


Hi Pavel,

thank you - was trying to use the stream I have directly, but saving it to file first works fine.

Have noticed that when I first call the DocumentCache method I get a couple of folders created with preview images (eg @x.Pdf and @800x.Pdf). If I then open the cached document in the annotation viewer I get different folders created (eg 90@852x.Pdf and 90@x.Pdf). Does this mean the cached document is not used and a new conversion happens when it is opened in the annotations viewer? Or is it just a resizing of the images from the original conversion (and thus much faster than converting it again)? Is there anything I can do to either the call on the DocumentCache or when setting up the annotations widget to enforce that the same cached files are used in both cases (so no further folders with different sized images are created when opening the doc in the annotations viewer)?



Hello Pete,

Thank you for coming back. We have checked the cache generating functional in the GroupDocs.Annotation and we can’t reproduce the issue - cache generated only once. To be able to reproduce the issue and help you to resolve it could you please share with us example of your code (full code of the view file, controller for the view and the code which saves the stream as a file).

Also will be helpful if you share with us description of the project: type (MVC, Web Forms etc.), version of the GroupDocs library that you use and properties which you use in the init method of the Annotation (Groupdocs.Web.Annotation.WidgetFactory.Initialize)

Thank you


Thanks Pavel,

I’m probably doing something silly. I’m just using the sample webforms project and have 2 separate pages:

cachefile.aspx which simply writes a file to disk then caches it:

DocumentCache dc = new DocumentCache(null, Server.MapPath("~/App_Data/"));
dc.GenerateImages(fileId + ext);

default.aspx that simply loads the cached file:

return new WidgetFactory()
.FilePath(fileId + “.pdf”)

After calling the cachefile.aspx page I have one folder with a single image (it is a single page document):


After I load the default.aspx page there are a couple of more folders created:


Each of the new folders have page_0.jpg files in them - both with different dimensions.

It’s no big deal at this stage, just wondered if I was doing something wrong with the caching or loading of the cached document…



Hello Pete,

Thank you for the code examples. Pleas try to use such code for the cache generating:
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"),
cacheDocument.GenerateHtml(_filePath, url, false);

Where _filePath - is your document name with extension (fileId + ext)

And then view the document as you do.

Thank you.


Thanks Pavel,

tried that and get some different folders and files created when it do the cache (html/css etc). However, still getting more folders with .jpg files created when I open the document in the annotations viewer, so guess I’m still not getting the viewer to use the pre-cached document. No big deal at this stage…

Is there really no way to get the viewer to work with documents in different folders? Looking to use this for viewing documents for different clients who’s data is currently segregated - so would prefer not to dump all files for different clients into the same location if I can help it.



Hello Pete,

Sorry but current version of the Annotation can’t work with different storages because changing the storage path require re-initializing of the Annotation, but it can be initialized only once (to re-init it you should restart your App pool what is not acceptable for the live App). If you will try to re-init Annotation on “live” App you will get error that the StructureMap is already used.

But we have a good news about it. Currently our product team works on the brand new Annotation which will have flexible storage functional - this should resolve a lot of issues with the storage. Unfortunately we can’t share the release date.

Thank you.


Hi Pavel,

does the DocumentCache.GenerateHTML() method work with the annotations viewer? I tried using it, but looks to me like the annotations viewer generates image files when the document is loaded rather than use the files created by DocumentCache. So just wanted to check if I’m doing something wrong or if the annotations viewer only works with cached images?

Just looking at options for generating less cached files. Using the images approach for a 10Mb PDF I basically need to store the PDF itself + 26Mb of files in the /processing folder + 38Mb of files in the /cache folder - adds up to a lot of space for one doc. I would need to keep the files round for a while (long running workflows), so was hoping there’s some way that the ‘html’ version can be used… Although from a quick test of the GenerateHtml() method it still produces 37Mb of files (8400 files) and takes a lot longer (40sec for images - ~300sec for html) so maybe that’s no improvement…



Hello Pete,

Thank you for the question. From your request I can assume that you have created HTML cache for the document and in the widget you doesn’t set to use HTML engine mode (because image cache generated). Bacuse of it you have HTML cache generating in the beck-end code and image cache generating at same time - since that you have such long time for processing. Unfortunately Annotation doesn’t supports HTML based mode (as a clean Viewer) and the GenerateHTML() method will not have sense, sorry for misunderstanding you earlier.

Thank you.