Exception while embedding fonts in parallel PDF Export (Plus MemoryLeak)
I have a large number of reports to export to PDFs (3 different reports to an internal ID. I have to run batches of 400+ internal IDs at a time). To speed things up, I tried to run the PDF export in parallel.
If I try to embedd fonts, I keep getting this error:
at FastReport.Fonts.TrueTypeFont.BuildGlyphIndexList(UInt16[] used_glyphs, Boolean decompose, Boolean collate, Boolean use_kerning, ArrayList& Indices, ArrayList& GlyphWidths) at FastReport.Fonts.TrueTypeFont.ReorderGlyphTable(IntPtr position, IList`1 keep_list, Boolean uniscribe, Byte[]& SavedGlyphs, Int16[]& ShortI2L, Int32[]& LongI2L) at FastReport.Fonts.TrueTypeFont.PackFont(IList`1 keep_list, Boolean uniscribe) at FastReport.Export.TTF.ExportTTFFont.GetFontData(Boolean subsetting) at FastReport.Export.Pdf.PDFExport.WriteFont(ExportTTFFont pdfFont) at FastReport.Export.Pdf.PDFExport.AddPDFFooter() at FastReport.Export.Pdf.PDFExport.Finish() at FastReport.Export.ExportBase.Export(Report report, Stream stream) at FastReport.Export.ExportBase.Export(Report report, String fileName) at FastReport.Report.Export(ExportBase export, String fileName) at cReporting.ExportReportToPdfForParallel(String _sReport, String sFont, String sExportFilePath, Int32 iColorSpace, DataSet dsReportDaten)
The calling function:
public void ExportReportToPdfForParallel(string _sReport, string sFont, string sExportFilePath, int iColorSpace, DataSet dsReportDaten) { using (EnvironmentSettings oEnvironmentSettings = new EnvironmentSettings()) { Report oCurrentReport = new Report(); oCurrentReport.LoadFromString(_sReport); oEnvironmentSettings.ReportSettings.ShowProgress = false; oEnvironmentSettings.ReportSettings.ShowPerformance = false; using (PDFExport oPdfExport = new PDFExport()) { oPdfExport.HideWindowUI = true; oPdfExport.PdfCompliance = PDFExport.PdfStandard.PdfA_2a; oPdfExport.EmbeddingFonts = true; oPdfExport.Restrictions = Restrictions.DontEdit; oPdfExport.AllowModify = false; oPdfExport.ColorSpace = (PDFExport.PdfColorSpace)iColorSpace; if (dsReportDaten != null) oCurrentReport.RegisterData(dsReportDaten); oCurrentReport.Prepare(); oCurrentReport.Export(oPdfExport, sExportFilePath); oCurrentReport.Delete(); oCurrentReport.GraphicCache?.Dispose(); dsReportDaten = null; } oCurrentReport.Dispose(); } }
On some machines, I'm also getting OutOfMemory Exceptions due to a memory leak somewhere during the
Export. Memory is not released until I close the programm.
It works fine on other machines and I cannot find a common factor.
These errors occur with any of the recent releases (19.4 to the most current of 20.1)
Can anybody help?
Comments
To clear the memory, try running each instance of the report in AppDomain: https://www.fast-report.com/en/blog/65/show/
This sounded good to me. Unfortunately, it didn't work as intended. The memory still isn't freed.
Do you unload the Domain after use? This is the true way to clear memory, since the garbage collector in C# does not work well.
Yes.
Try using the latest version (2020.1.13). Recently, we fixed a memory leak when using Bold fonts.
I downloaded 2020.1.14 today. Still no change.