Persistent CustomTempFonts Folder Growth Issue in GroupDocs.Viewer 24.6.0 and 24.9.0 for .NET Framework

I also encountered this problem. I came across it in GroupDocs.Viewer version 24.6.0 for .NET Framework 4.6.2. I upgraded to the latest version 24.9.0 and the problem still occurs. On some environments the folder grows here: c:\Windows\Temp\CustomTempFonts, on others here: c:\Users\[user]\AppData\Local\Temp\CustomTempFonts. Do you want code to reproduce this on, or is the problem reproducible enough from earlier posts? Is there any workaround? When will this issue be fixed in the product?

Hi @jiri.darmovzal

Sorry for the inconvenience. We’ve logged this issue under “VIEWERNET-5060” moniker in our internal tracking system and started to investigate it.

We can see the same issue on our side, but you will be very helpful if you tell us files of which format(s) are causing this issue on your side? Source code will also be helpful, as it can narrow down the area our research.

Also, which size has the “CustomTempFonts” folder in your case?

With best regards,
Denis

Hi @denisgvardionov,

I am using this code:

public class Renderer : IRenderer
{
    public void Render(string outputPath, string url, string fileName, byte[] content)
    {
        License license = new License();

        string resourceName = "GroupDocs.Viewerfor.NET.lic";
        Assembly assembly = Assembly.GetExecutingAssembly();
        using (Stream stream = assembly.GetManifestResourceStream(resourceName))
        {
            license.SetLicense(stream);
        }

        using (MemoryStream stream = new MemoryStream(content))
        {
            LoadOptions loadOptions = new LoadOptions();
            if (Path.GetExtension(fileName).Equals(".txt", StringComparison.OrdinalIgnoreCase))
            {
                loadOptions.FileType = FileType.TXT;
            }

            IPageStreamFactory pageStreamFactory = new PageStreamFactory(Path.Combine(outputPath, "page_{0}.html"));
            IResourceStreamFactory resourceStreamFactory = new ResourceStreamFactory(Path.Combine(outputPath, "page_{0}/resource_{1}"), url + "/page_{0}/resource_{1}");

            using (Viewer viewer = new Viewer(stream, loadOptions))
            {
                HtmlViewOptions viewOptions = HtmlViewOptions.ForExternalResources(
                    pageStreamFactory,
                    resourceStreamFactory);
                viewer.View(viewOptions);

                ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
                ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);
            }
        }
    }
}

internal class PageStreamFactory : IPageStreamFactory
{
    public string PageFileFormat { get; }
            
    public PageStreamFactory(string pageFileFormat)
    {
        PageFileFormat = pageFileFormat;
    }

    public Stream CreatePageStream(int pageNumber)
    {
        return new MemoryStream();
    }

    public void ReleasePageStream(int pageNumber, Stream pageStream)
    {
        try
        {
            using (MemoryStream ms = pageStream as MemoryStream)
            {
                string html = Encoding.UTF8.GetString(ms.ToArray());
                html = html.Replace("overflow:hidden;", string.Empty);

                string filePath = string.Format(PageFileFormat, pageNumber);

                System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
                fileInfo.Directory.Create();
             
                File.WriteAllText(fileInfo.FullName, html);
            }
        }
        finally
        {
            pageStream.Dispose();
        }
    }
}

internal class ResourceStreamFactory : IResourceStreamFactory
{
    public string ResourceFileFormat { get; }
    public string ResourceUrlFormat { get; }

    public ResourceStreamFactory(string resourceFileFormat, string resourceUrlFormat)
    {
        ResourceFileFormat = resourceFileFormat;
        ResourceUrlFormat = resourceUrlFormat;
    }

    public Stream CreateResourceStream(int pageNumber, Resource resource)
    {
        return new MemoryStream();
    }

    public string CreateResourceUrl(int pageNumber, Resource resource)
    {
        return string.Format(ResourceUrlFormat, pageNumber, resource.FileName);
    }

    public void ReleaseResourceStream(int pageNumber, Resource resource, Stream resourceStream)
    {
        try
        {
            string filePath = string.Format(ResourceFileFormat, pageNumber, resource.FileName);

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
            fileInfo.Directory.Create();

            using (FileStream fileStream = File.Create(filePath))
            {
                resourceStream.Seek(0, SeekOrigin.Begin);
                resourceStream.CopyTo(fileStream);
            }
        }
        finally
        {
            resourceStream.Dispose();
        }
    }
}

I had to use PageStreamFactory as a workaround for the bug (see this post for details).

The problem occurs only with PDF files. Other file types do not create folders under CustomTempFonts. I am attaching a sample PDF file, which generates 141 folders in CustomTempFonts with an overall size of 2.3 MB. Different PDF files generate different numbers of folders. With every conversion, new folders are created, causing the size of CustomTempFonts to increase indefinitely.

compressed.tracemonkey-pldi-09.pdf (992.5 kB)

Best regards,
Jiri

Hi @jiri.darmovzal

Thank you very much for the attached PDF file and source code, you have confirmed our suspicions. Actually, temp font files are generated for every PDF file we have checked, and this has no relation to the configuration of the HtmlViewOptions. The only workaround we see now is to use the GroupDocs.Viewer on .NET 6.0+ - in that case the “CustomTempFonts” will not be created at all. But, of course, we treat this issue as a bug and already started to work on it.

Sorry for the inconvenience.

With best regards,
Denis