We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

Viewer is not rendering all pages on Azure deployment and local inconsistently

Viewer is not rendering all pages on Azure deployment. It works fine when running local the first debug time through, then the local also stops rendering any page after 1. Rendering pages also takes a significant amount of time using embedded resources.

Please provide accurate sample code to render an entire document, regardless of type to the viewer. We do not have the option to use pagination or cache as these are classified documents, and the URLs cannot be exposed publicly so all data must be sent back via the API.

It appears as though sometimes the logic to returnValue += Encoding.UTF8.GetString(bytes) only gets called once, and does not iterate through the streams pages. This is inconsistent as other times it does. What am I doing wrong?

using (MemoryStream fileStream = new MemoryStream())
{
    await cloudBlockBlob.DownloadToStreamAsync(fileStream, accessCondition, blobRequestOptions, operationContext);
    fileStream.Position = 0;
    fileStream.Flush();
    cloudBlobContainer = null;
    cloudBlockBlob = null;
    
    fileStream.Position = 0;
    fileStream.Flush();
    LoadOptions loadOptions = new LoadOptions(FileType.FromExtension(Path.GetExtension(attachment.FilePath)));
    using (Viewer viewer = new Viewer(fileStream, loadOptions))
    {
            HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources(
            (_) => new MemoryStream(),
            (int pageNumber, Stream pageStream) =>
            {
                var bytes = ((MemoryStream)pageStream).ToArray();
                returnValue += Encoding.UTF8.GetString(bytes);
            });

        viewOptions.Minify = true;
        viewOptions.RenderToSinglePage = false;
        viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForOnePagePerSheet();
        viewOptions.SpreadsheetOptions.SkipEmptyColumns = true;
        viewOptions.SpreadsheetOptions.SkipEmptyRows = true;
        viewOptions.SpreadsheetOptions.RenderGridLines = true;
        viewOptions.SpreadsheetOptions.RenderHeadings = true;
        viewOptions.SpreadsheetOptions.TextOverflowMode = TextOverflowMode.AutoFitColumn;
        viewOptions.RenderResponsive = true;

        viewer.View(viewOptions);
    }                                
}


**********************
This Topic is created by vladimir.litvinchik using Email to Topic tool.

@abcmk

It depends on the count of document pages that are going to be exported to HTML. You can try to Set up logging to check how many pages are actually processed.

As soon as we have a sample code we’ll update you.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

  Issue ID(s): VIEWERNET-4213

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

When inspecting the “returnValue” in the debugger, its only doing the first page. We want to render ALL pages, all the time.

@abcmk

Got it, do you have any sample file that we can use or at least a file type that you’re trying to render?

This is reproducible in both word and excel files. We are able to make it happen with a simple word doc and a few characters and pages. One notable attribute is these word documents do have headers and footers and images in them, such as a company logo at the top and basic page numbers, etc.

Could it be the type of memory stream we are using from Azure?

@abcmk

Can you please attach the sample file you’re able to reproduce this issue?

We do not recommend using OpenReadAsync since it reads just a part of a stream and affects the performance. But, as I can see from your code snippet you’re already using DownloadToStreamAsync that reads a stream into memory.

Vlad,

I can share a document if I remove some PI from it but I’m not sure it will help. I am experiencing this with every doc in the system that has more than 1 page. Randomly, and I mean randomly, all pages render in my local IDE but it seems to happen once then it never happens again.

Could it be a cache problem, or something directly related to the embedded resources running out of memory or anything? Trying to think of anything outside of the realm of normalcy.

I should note we just had another customer report this issue, as it was not happening previously and we did not make any production updates. This leads me to think its a server side caching issue.

@abcmk

Caching may be the issue. Try to enable caching, possibly it will give some additional information. At least you’ll see how many pages are rendered.

Hi Vlad,

[TRACE] Rendering into HTML with embedded resources.
[TRACE] Opening document.
[TRACE] Document is loaded.
[TRACE] Applying options.
[TRACE] Converting page 1.
[TRACE] Page 1 conversion completed.
[TRACE] Releasing resources.

It does not appear to ever go for any more pages in the document. I can confirm the file is correct coming into memory at 122190 bytes and only ever renders the first page.

Is there a way to clear the existing cache? I did not setup a file cache or anything specific for this yet, and just using whatever defaults exist.

One more tid bit of information: This occurred after I made the move to .net core 6 from 5. I can confirm this issue still persists in older code branches which is no help.

Looking for suggestions on how to clear any temp files you may generate from the server and also how to prevent this going forward.

Another Update:

I removed Azure from the equation and used a local copy of the file. The same issue exists, it does not do more than one page.

However, another file I have watermarks on it from the Watermarker API and the Viewer errored saying the file was corrupt when using local disk. I do not get that error when using a memory stream, as in my production code we download the memory stream, pass it through your watermarker first, then into the viewer. These are not related as I have removed the watermarking code entirely and the code i sent is what I am running locally.

I have attached the specific file I have been reproducing this with. thedoc2.docx (18.7 KB)

Remove all of my application code:

 public IActionResult Test()
    {
        // Create logger and specify the output file
        FileLogger fileLogger = new FileLogger("viewerOutput.log");
        string html = null;
        string outputDirectory = @"C:\src";
        string cachePath = Path.Combine(outputDirectory, "viewer-cache");
        string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
        FileCache cache = new FileCache(cachePath);
        ViewerSettings settings = new ViewerSettings(cache, fileLogger);
        LoadOptions loadOptions = new LoadOptions(FileType.FromExtension(Path.GetExtension(".docx")));

        using (Viewer viewer = new Viewer(@"C:\src\thedoc2.docx", loadOptions, settings))
        {
            HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources(
            (_) => new MemoryStream(),
            (int pageNumber, Stream pageStream) =>
            {
                var bytes = ((MemoryStream)pageStream).ToArray();
                html += Encoding.UTF8.GetString(bytes);
            });

            //viewOptions.Minify = true;
            viewOptions.RenderToSinglePage = true;
            //viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForOnePagePerSheet();
            //viewOptions.SpreadsheetOptions.SkipEmptyColumns = true;
            //viewOptions.SpreadsheetOptions.SkipEmptyRows = true;
            //viewOptions.SpreadsheetOptions.RenderGridLines = true;
            //viewOptions.SpreadsheetOptions.RenderHeadings = true;
            //viewOptions.SpreadsheetOptions.TextOverflowMode = TextOverflowMode.AutoFitColumn;
            viewOptions.RenderResponsive = true;


            viewer.View(viewOptions);
        }

        return View(html);
    }

image.png (347.9 KB)

[TRACE] Rendering into HTML with embedded resources.
[TRACE] Opening document.
[TRACE] Document is loaded.
[TRACE] Applying options.
[TRACE] Converting page 1.
[TRACE] Page 1 conversion completed.
[TRACE] Releasing resources.
[TRACE] Rendering into HTML with embedded resources.
[TRACE] Opening document.
[TRACE] Document is loaded.
[TRACE] Applying options.
[TRACE] Page 1 not found in cache - converting.
[TRACE] Releasing resources.

Does not render more than 1 page on 22.8.0, 22.9.0, 22.12.0

@abcmk

Thank you for attaching the code snippet and sample file. I have found that this is a bug when the following options are set.

viewOptions.RenderToSinglePage = true;
viewOptions.RenderResponsive = true;

As a temporary workaround you can disable one of the options viewOptions.RenderToSinglePage = false; or viewOptions.RenderResponsive = false;.

This issue is going to be fixed in the upcoming version 23.1. The release is planned by the end of the next week.

@abcmk

This issue has been fixed in GroupDocs.Viewer 23.1. The package is available at NuGet and GroupDocs.Downloads.

Have a nice day!