This is a migrated thread and some comments may be shown as answers.

System.OutOfMemoryException export report to PDF

8 Answers 911 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
IT
Top achievements
Rank 1
IT asked on 02 Jun 2017, 09:10 PM

Hi There, 

We Telerik Reporting version to convert a data set in csv format and exporting it to PDF format.

There are around 41,000 rows in the csv file. And it generates around 1,000 pages in PDG format. 

controls used in the report are only csvDataSource, crosstab and textbox. No images used.

There are 2 groups, by store and then fiscal month. They are used for the bookmarks in PDF format report.

It takes much time generates the report and receiving System.OutOfMemoryException while exporting the report to PDF. 

But if I reduce the number of records in the source csv file, I'm able to export the data to PDF, so the code is working.

The requirement is to generate all data in one single PDF report as it's enterprise level report, filter/ report parameter is not an option in this case.

See attached screenshot of the error message.

Can anyone know this issue and give some suggestions?

 

Thanks a lot!

Susie

8 Answers, 1 is accepted

Sort by
0
IT
Top achievements
Rank 1
answered on 03 Jun 2017, 12:19 AM

Here is the error message along with the screen shot of physical memory status in the server:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Windows.Forms.Internal.DeviceContexts.AddDeviceContext(DeviceContext dc)
   at System.Windows.Forms.Internal.DeviceContext..ctor(IntPtr hDC, DeviceContextType dcType)
   at System.Windows.Forms.Internal.WindowsGraphics.FromHdc(IntPtr hDc)
   at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.ColorOptions.Calculate()
   at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintWorker(PaintEventArgs e, Boolean up, CheckState state)
   at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintUp(PaintEventArgs e, CheckState state)
   at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(PaintEventArgs pevent)
   at System.Windows.Forms.ButtonBase.OnPaint(PaintEventArgs pevent)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MyTestReportHostForm
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/Test/Debug/MyTestReportHostForm.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34251 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34270 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Telerik.Reporting
    Assembly Version: 11.1.17.503
    Win32 Version: 11.1.17.503
    CodeBase: file:///D:/Test/Debug/Telerik.Reporting.DLL
----------------------------------------
Telerik.ReportViewer.WinForms
    Assembly Version: 11.1.17.503
    Win32 Version: 11.1.17.503
    CodeBase: file:///D:/Test/Debug/Telerik.ReportViewer.WinForms.DLL
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Web
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34280 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
ReportLibrary1
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/Test/Debug/ReportLibrary1.DLL
----------------------------------------
Anonymously Hosted DynamicMethods Assembly
    Assembly Version: 0.0.0.0
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

0
Stef
Telerik team
answered on 05 Jun 2017, 04:54 PM
Hi Susie,

I believe the error is the same as in http://docs.telerik.com/reporting/troubleshooting-windows-forms-report-viewer#-an-error-has-occurred-while-rendering-the-report-system-runtime-interopservices-externalexception-a-generic-error-occurred-in-gdi-or-system-outofmemoryexception-exception-of-type-system-outofmemoryexception-was-thrown-error-on-displaying-a-report
It is a result from the Image rendering used by the WinForms ReportViewer control.


In general, the Table/List/Crosstab item is rendered into a single continuous page and if the elements are too many, the GDI may not be able to handle the image generation. Test switching the viewer's ViewMode to PrintPreview and/or export programmatically the report.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
IT
Top achievements
Rank 1
answered on 05 Jun 2017, 10:09 PM

Hi Stef, 

I tried to generate the PDF Programmatically. But still getting the same error message.

See attached screen shot.

Is there a way we can save cache to a file in the hard driver instead of memory? I updated the config file as below, but it seems never looked to the config file when the application runs.

 

Thanks,

Susie

app.config file:

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="Telerik.Reporting" type="Telerik.Reporting.Configuration.ReportingConfigurationSection, Telerik.Reporting, Version=11.1.17.503, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>
  <Telerik.Reporting>
    <Cache provider="File" BasePath="C:\Temp\" />
    <cache provider="File" BasePath="C:\Temp\"/>
    <assemblyReferences>
      <add name="ReportLibrary1" version="1.0.0.0" />
    </assemblyReferences>
    <SessionState provider="" />
    <restReportService>
      <storage provider="" />
      <reportResolver provider="" />
    </restReportService>
    <extensions>
      <render>
        <extension name="PDF">
          <parameters>
            <parameter name="JavaScript" value="app.execMenuItem('ShowHideBookmarks')" />
          </parameters>
        </extension>
      </render>
    </extensions>
  </Telerik.Reporting>
</configuration>

 

0
Stef
Telerik team
answered on 06 Jun 2017, 03:19 PM
Hi,

In such case, the data and the report processing cannot be handled by the machine. In general, the report processing keeps the retrieved data and all generated resources in memory until the rendering ends. Thus you need to reduce the amount of data processed in a report at once, or to assure the machine has enough CPU and memory to handle the document generation.

Please post the code for generating the report in order to check its settings and to suggest you changes which can improve the performance.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
IT
Top achievements
Rank 1
answered on 06 Jun 2017, 09:57 PM

Hi Stef, 

The testing server which is hosting the report generation part do have enough CPU (4)and physical memory(20GB). When the error comes CPU usage is around 50% and Memory usage is only 35%. 

Is there a way I can send you the report design code? Maybe you can help us to improve the performance? I'm not able to attach the zip file here.

Below is the code to export report to PDF:

 private void ExportToPDF(Telerik.Reporting.Report reportToExport)
        {
            ReportProcessor reportProcessor = new ReportProcessor();
            Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = reportToExport;
                       
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);



            string fileName = "Test_Report_" + System.DateTime.Today.ToString("ddMMyyyy") + "." + result.Extension;

            string path = System.IO.Path.GetTempPath();
            string filePath = System.IO.Path.Combine(path, fileName);

            using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
            {
                fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            }
            
        }

 

Do you have any idea on the app.config file I was talking about above? Instead of rendering into memory, can we use a file?

0
Accepted
Stef
Telerik team
answered on 07 Jun 2017, 12:16 PM
Hi,

The configuration settings you posted are related to the Reporting Engine's cache mechanism.
If there are images during the processing or you render in a multi-document format like HTML, ready resources are placed in the file system or in a database (depends on the cache configuration).
In the case of Image rendering (the preview of the WinForms ReportViewer and the available Report Designers), and PDF rendering that is based on the Image rendering, there are little to no resources which will be placed physically on the machine.
We are planning changes which will improve the performance in R3 2017 (September 14th).

For the time being, you can test splitting the data and creating smaller PDF files or to export asynchronously.


Please feel free to open a support ticket and to send us the problematic report to check its settings for possible optimizations.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Roshan
Top achievements
Rank 1
answered on 09 Nov 2018, 12:24 AM

Hi Telerik team,

we have a similar issue with Silverlight and get an Out of memory exception when trying to show a pdf preview of large data. We are using version 9.2.15.930 of telerik, could you let us know if the later versions than we have handles larger amount of data?

Thank you,

Roshan

0
Todor
Telerik team
answered on 13 Nov 2018, 01:43 PM
Hi Roshan,

We have improved the overall performance up to 25% in all supported document formats starting with Telerik Reporting R3 2017 (version 11.2.17.913) . Check also Sneak Peek: New Features in Telerik Reporting R3 Beta 1 blog post.
Note that we have introduced memory usage optimization for the PDF rendering extension, which implies better handling of larger data amounts.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
IT
Top achievements
Rank 1
Answers by
IT
Top achievements
Rank 1
Stef
Telerik team
Roshan
Top achievements
Rank 1
Todor
Telerik team
Share this question
or