How to workaround a PDF export font issue on Windows Azure

Exporting  reports to PDF  format  from application deployed to Windows Azure WebSites sometimes may result in OutOfMemoryException. This problem is mainly caused by a bug in Azure WebSites platform. Please check the following article for your reference:

https://social.msdn.microsoft.com/forums/azure/en-US/b4a6eb43-0013-435f-9d11-00ee26a8d017/report-viewer-error-on-export-pdf-or-excel-from-azure-web-sites

In this article we will describe the workaround that can be used in such situation. Our example is based on the scenario where GDI+ calls are performed for getting font metrics. The main idea is to bypass getting the font metrics through GDI+ calls by creating a cache file that contains the required fonts.

 

1) First of all we need to create a cache class that should perform writing a cache to a file. This can be done as displayed in the following article:

http://helpcenter.perpetuumsoft.com/KB/a516/improving-pdf-export-performance.aspx


2) The next step is to create a font ranges cache on a local PC by calling the following method:

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

 

3) After the font ranges cache is created it should be transferred to Azure hosting so it can be used by the application.

 

4) To avoid the possible font problems, check to make sure that the required fonts are added to a  web site custom fonts folder ( prior to performing step 2) and your PDF export is set  to read these font files.

 The export can be set from code as follows:

PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter.AddCustomFontFolder(Server.MapPath("/Fonts"), true);

Please note, this method should be called prior to creation of cache file.

 

Add Feedback