DocumentCache not working as expected

In order to speed up the viewer, we coded the ability to pre-cache the documents before opening them in the viewer. This is the code used:


DocumentCache dc = new DocumentCache(null, webStorageLocation);
dc.GenerateHtml(documentPath, “test”, false);


This creates the temp\Cache folder in the proper location on disk. However, when you go to open the file using the viewer, it only renders text - there is no images or formatting.

If I delete the temp\Cache folder from the location on disk and allow the viewer to create the cache when opened, the file shows correctly with images and formatting.

This is the code for the viewer itself:
<script type=“text/javascript”>
function OnDocumentSelect(fileToLoad) {
        <span style="color:#57a64a;">//fileToLoad = '\\' + fileToLoad ;</span>
        <span style="color:#57a64a;">//alert('fileToLoad ' + fileToLoad);</span>
        <span style="color:#569cd6;">var</span> localizedStrings <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">;</span> <span style="color:#569cd6;">var</span> thumbsImageBase64Encoded <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">;</span>
        $<span style="color:#b4b4b4;">(</span><span style="color:#d69d85;">'#filePreview'</span><span style="color:#b4b4b4;">).</span>groupdocsViewer<span style="color:#b4b4b4;">({</span>
            localizedStrings<span style="color:#b4b4b4;">:</span> localizedStrings<span style="color:#b4b4b4;">,</span> thumbsImageBase64Encoded<span style="color:#b4b4b4;">:</span> thumbsImageBase64Encoded<span style="color:#b4b4b4;">,</span>
            filePath<span style="color:#b4b4b4;">:</span> fileToLoad<span style="color:#b4b4b4;">,</span> quality<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">100</span><span style="color:#b4b4b4;">,</span> showThumbnails<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> openThumbnails<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> initialZoom<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">100</span><span style="color:#b4b4b4;">,</span> zoomToFitWidth<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span>
            onlyShrinkLargePages<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> zoomToFitHeight<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> width<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">1000</span><span style="color:#b4b4b4;">,</span> height<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">900</span><span style="color:#b4b4b4;">,</span> backgroundColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> showFolderBrowser<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> showPrint<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span>
            showDownload<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> showZoom<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> showPaging<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> showViewerStyleControl<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> showSearch<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> preloadPagesCount<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">1</span><span style="color:#b4b4b4;">,</span> preloadPagesOnBrowserSide<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span>
            convertWordDocumentsCompletely<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> viewerStyle<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">1</span><span style="color:#b4b4b4;">,</span> supportTextSelection<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> usePdfPrinting<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> toolbarButtonsBoxShadowStyle<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span>
            toolbarButtonsBoxShadowHoverStyle<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> thumbnailsContainerBackgroundColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> thumbnailsContainerBorderRightColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> toolbarBorderBottomColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span>
            toolbarInputFieldBorderColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> toolbarButtonBorderColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> toolbarButtonBorderHoverColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> thumbnailsContainerWidth<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">0</span><span style="color:#b4b4b4;">,</span> jqueryFileDownloadCookieName<span style="color:#b4b4b4;">:</span> <span style="color:#d69d85;">'jqueryFileDownloadJSForGD'</span><span style="color:#b4b4b4;">,</span>
            showDownloadErrorsInPopup<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> showImageWidth<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> showHeader<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> minimumImageWidth<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">0</span><span style="color:#b4b4b4;">,</span> enableStandardErrorHandling<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> useHtmlBasedEngine<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span>
            useHtmlThumbnails<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> useImageBasedPrinting<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span> fileDisplayName<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> downloadPdfFile<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> searchForSeparateWords<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> preventTouchEventsBubbling<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span>
            useInnerThumbnails<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> watermarkText<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> watermarkColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> watermarkPosition<span style="color:#b4b4b4;">:</span> <span style="color:#d69d85;">'Diagonal'</span><span style="color:#b4b4b4;">,</span> watermarkFontSize<span style="color:#b4b4b4;">:</span> <span style="color:#b5cea8;">0</span><span style="color:#b4b4b4;">,</span> printWithWatermark<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span>
            supportPageReordering<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> searchHighlightColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> currentSearchHighlightColor<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">null</span><span style="color:#b4b4b4;">,</span> treatPhrasesInDoubleQuotesAsExactPhrases<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span>
            usePngImagesForHtmlBasedEngine<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> showOnePageInRow<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> loadAllPagesOnSearch<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> useEmScaling<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> ignoreDocumentAbsence<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> supportPageRotation<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">true</span><span style="color:#b4b4b4;">,</span>
            useRtl<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> useAccentInsensitiveSearch<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> useVirtualMode<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> supportListOfContentControls<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> supportListOfBookmarks<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span><span style="color:#b4b4b4;">,</span> embedImagesIntoHtmlForWordFiles<span style="color:#b4b4b4;">:</span> <span style="color:#569cd6;">false</span>
        <span style="color:#b4b4b4;">});</span>
    <span style="color:#b4b4b4;">}</span> <span style="color:gray;"></</span><span style="color:#569cd6;">script</span><span style="color:gray;">></span></span></pre><br><br>I have tried also to use <br><pre style="font-family:Consolas;font-size:13;color:gainsboro;background:#1e1e1e;"><span style="background-color: rgb(0, 0, 0);">dc<span style="color:#b4b4b4;">.</span>GenerateImages(dco<span style="color:#b4b4b4;">.</span>NewFileName, <span style="color:#569cd6;">null</span>, <span style="color:#569cd6;">null</span>, <span style="color:#b5cea8;">100</span>);

rather than .GenerateHtml and have no luck with this either. For some reason I am not able to access the method .GeneratePdfVersion so I have not tried this. Any help appreciated. Thanks
Hello ,

Thank you for your inquiry.

Please investigate this article, for how to use DocumentCache class for generating cache of files for the GroupDocs.Viewer for .NET library . And you will find that you should use also GenerateImages method , to generate the image content

If you will have more questions please feel free to contact us.

----------

Best regards,
Evgen Efimov

http://groupdocs.com
Your Document Collaboration APIs
Follow us on LinkedIn, Twitter, Facebook and Google+

As requested in the support chat I’ve attached an example of a document that does not render images properly after precaching using the code I’ve written above.

Hello Christina,
Thank you for the file example. please try to use such code for cache generating:
DocumentCache dc = new DocumentCache(null, Server.MapPath(“~/testfiles”));
dc.GenerateHtml(“1.pdf”, http://localhost:2222, true, true, true);
And please check this screenshot for the code description.
Best regards.

Thank you for your response but this is still not working. Capture.PNG is the result. Capture2.PNG is the result when the document is not pre-cached. Capture2.PNG is what it should look like.

Hello Christina,


I have prepared an example project with functionality that you need. Please download it here. When you will run it the Default web page will be loaded and cache for your document will be generated, then you will see the link (the only content of the web page) to view the document with generated cache.

Also try to delete already created cache and regenerate it in your solution.

If this will not help you - please share with me your project, I will fix it for you.

Best regards.

Thanks Pavel,
Still having some troubles, let me see if i can explain without sending the project…
Here is your code:
DocumentCache dc = new DocumentCache(null, Server.MapPath("~/testfiles"));
dc.GenerateHtml(“26ed1edd-0248-47fa-9118-99ed2909e8bb.pdf”, http://localhost:2222,true, true, true);
Here is my code:
DocumentCache dc = new DocumentCache(null, webStorageLocation);
dc.GenerateHtml(documentPath, http://localhost/ep, true, false, true);

Please note: We use MVC and no HTTPHandlers. I am generating the cache using a windows service vs how you generate using the webapp. Therefore I am not able to use Server.MapPath object. I’m not sure if maybe this is part of the issue.
The documentPath object I use is exactly the same format as yours: “filename.pdf”
the webStorageLocation is in this format: “\folder\folder2\WebCache\CG”
A side by side comparison of the .html generated using both the window services pre-caching method and the group docs cache on demand method show the .html is the same, as is the .CSS.
Any thoughts?

Hello Christina,

Thank you for the explanation. Could you pleas say if the URL “http://localhost/ep” is your root URL of the solution (it opens the main page)?
Does the same path “\folder\folder2\WebCache\CG” you have set as root storage path for the Viewer?
Also to ensure can you please use cache generating in the web app as I do, to check if it’s a reason of the issue.
If this will not help you - I definitely need example of your project and of the win service (only cache generating part).
Thank you.

as for your first question, yes the URL opens to the root of the solution.
The path \\folder\folder2... is also set as the root storage path.
I did try to use cache generating in the web as you do, but it's creating the same problem. I did, however find the error that is being thrown at the time of viewing the cached document:

2015-10-21 14:20:32,046 [5] ERROR ep.MvcApplication - Error A public action method 'GetResourceForHtmlHandler' was not found on controller 'Groupdocs.Web.UI.Controllers.GroupdocsViewerController'. at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar)
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

This is relevant because the .html file created by the cache has this at the top:
GetResourceForHtmlHandler?documentPath=0b925953-1c51-45aa-9e11-7ba42f75b21a.pdf&resourcePath=2_1.png&relativeToOriginal=false" alt="" class="pg1htm04" />

Hello,


Thank you for this details. According on the error I can assume that you have set the Viewer to use the handlers, please double check next:

1. In the Application_Start you have Viewer.InitRoutes(); as a first code line before setting the root storage for the Viewer.
2. In the view you have set UseHttpHandlers(false) here: @Html.CreateViewerScriptLoadBlock().LoadJquery().LoadJqueryUi().UseHttpHandlers(false)
3. In the GenerateHtml method you have set false for both
bool usePngImagesForHtmlBasedEngine and bool useHttpHandlers = true,

If this will not help you please share the solution example.

Best regards.

This is still not working as expected. Myself and a team member will try to debug it more on Monday and we will get back to you next week with a little sample of the project if necessary

Hello Christina,


Thank you for the notification. yes, please come back to us with the sample and I will be glad to check and fix it for you.

Best regards.