Improving PDF Export performance

In order to speed up the process of generating pdf file, we have created fonts cache. Expense of this productivity will save you up to dozen of seconds.

 
For example you can implement this feature as follows:class FontsRepo : PerpetuumSoft.Framework.Caching.IFrameworkCache
        {
            private string repoPath = @"C:\temp";
            public void Add(string key, object cacheObject)
            {
                FileStream stream = new FileStream(Path.Combine(repoPath,key),FileMode.Create);
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, cacheObject);
                stream.Close();
            }
 
            public object this[string key]
            {
                get
                {
                    FileStream stream = new FileStream(Path.Combine(repoPath, key), FileMode.Open);
                    BinaryFormatter formatter = new BinaryFormatter();
                    return formatter.Deserialize(stream);
                }
            }
 
            public bool ContainsKey(string key)
            {
                return File.Exists(Path.Combine(repoPath,key));
            }
 
            public object[] GetValues()
            {
                throw new NotImplementedException();
            }
 
            public string[] GetKeys()
            {
                throw new NotImplementedException();
            }
 
           
 
            public void RemoveByKey(string key)
            {
                File.Delete(Path.Combine(repoPath,key));
            }
 
            public void Clear()
            {
                throw new NotImplementedException();
            }
 
 
            public void Remove(object obj)
            {
                throw new NotImplementedException();
            }
        }
 

In order to override default PDF export cache (which is disabled by default) you can use the following line:

PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter.Cache = new FontsRepo(); 

In order to force cache creating you can use the following line, but is not necessary, because cache creation will happen only once.

PerpetuumSoft
.Reporting.Export.Pdf.Writer.PdfWriter.LoadFonts();
 

Add Feedback