OutOfMemoryException when exporting large PDF

Posted by: halamakki on 14 September 2017, 6:41 pm EST

    • Post Options:
    • Link

    Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Hello,

    I have a report in my web application (HtmlViewer), of over 30000 pages that I want to export to PDF.

    I'm getting an OutOfMemoryException after several minutes.

    How can I fix this issue?

    Thanks in advance,

    Hala[/activereports_archive]

  • Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Hello Hala,

    I tried replicating the issue mentioned by you and was unable to do so.

    Please refer to the attached sample wherein a report of 30000 pages have been run and exported to PDF file. The sample was run on a Win7 + 32bit machine and no Memory Exception was observed.

    I would request you to please try running the sample at your end and see if you still face any issues using this sample.

    Also, I would suggest you to run your sample on more than one system and see if the issue is not specific to a machine. In case the issues persists, then you are requested to please share your sample application with us.

    Also, mention the machine configuration of your system.

    Regards,

    Mohita[/activereports_archive]

    2014/05/Test_ExportLargeReport.zip

  • Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Hello Mohita,

    The sample you attached does not represent my case, I’m deploying my report in a ASP .net application, I’m getting a System.OutOfMemoryException from the browser.

    Also my report has different types of fields (textbox, datamatrix, images, …), and I’m getting all the data from an SQL Server, so the report takes about 4 minutes to be displayed, and about 15 minutes to show the number of pages in the toolbar;

    After waiting, I just click on the button to export it (the exact same event handler as the one in your sample), and I get immediately the exception.

    When trying the same code, with the same report, but with less data (deploying the report for smaller number of invoices), I get no error, and I get my PDF exported successfully.

    I’m working on a Win7 64 bit, RAM 16 GB, Intel Core i5 3.20 GHz.

    What else do you need to know about the machine?

    I’m trying your sample right now, but I don’t think it would help me.

    Waiting for your response,

    Thanks in advance,

    Hala[/activereports_archive]

  • Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Now that I’m using SectionReports, I’m getting a System.OutOfMemoryException at the end of deploying (the report doesn’t display).

    I searched over the internet, and the documentation, and I found a very interesting solution, which is using the disk cache to reduce memory use.

    It’s mentionned that this would be useful if the report had more than 100 pages, otherwise it’s useless.

    Now in a normal scenario, it would be implemented this way:

    [csharp]

    protected void ShowReport()

    {

    rpt = new SectionReport();

    rpt.Document.CacheToDisk = true;

    rpt.Document.CacheToDiskLocation = "C:\Temp";

    rpt.Run();

    webViewer.Report = rpt;

    }

    [/csharp]

    In my case, I have 2 parametered SectionReports, that I merge for each instance of the parameter, if they meet certain conditions (that’s why I need to loop and run both reports for every parameter’s value).

    A single parametered report doesn’t result in more than 10 pages.

    Here’s my code:

    [csharp]

    protected void ShowReport()

    {

    PagesCollection pc = new PagesCollection();

    // this will loop for at least 15 000 times, and it takes about 3 and a half hour

    foreach (string _param in _params)

    {

    rpt1 = new SectionReport1(_param);

    rpt1.Run();

    rpt2 = new SectionReport2(_param);

    rpt2.Run();

    if(rpt2.meetsConditions == true && rpt1.meetsConditions == true)

    {

    pc.AddRange(rpt1.Document.Pages);

    pc.AddRange(rpt2.Document.Pages);

    }

    }

    rpt1.Document.Pages.Clear();

    // pc will contain at least 30 000 pages

    rpt1.Document.Pages.AddRange(pc);

    webViewer.Report = rpt1;

    }

    [/csharp]

    Could anyone tell me please where to implement this solution in my code?

    P.S. The code is working fine when looping on fewer parameters.[/activereports_archive]

  • Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Hala,

    Sorry for missing this post. Can you please provide me some details about your report design? Does your report contain images or subreports? When setting CacheToDisk property to true, temporary file is created only after report engine allocated 500 images in memory, plus some images were swapped to memory (to reduce GDI resources usage) and took over 100MBytes.

    One option which you may try to break your reports into smaller parts and then export them to PDF. Finally you can combine all the PDF’s together using any PDF stitching tool.

    Let me know your observations.

    Regards,

    Sankalp[/activereports_archive]

  • Posted 14 September 2017, 6:41 pm EST

    [activereports_archive]Hello Sankalp,

    Thank you for your reply, actually after setting the Cache Disk property to true, the OutOfMemory Exception disappeared.

    Then I faced another problem, the resulting pdf file contained blank pages (if the report contains more than 100 pages); I solved this issue by using Active Reports hotfix v8.0.352.0

    Then I ran tests for larger reports (about 30000 pages, with images on them), so the result was a corrupted pdf file of a 0 kb, that won’t open.

    So eventually what I did is what you are suggesting, I break the result in 3 PageCollections, export each one to pdf, and then I use iTextSharp library to merge the 3 pdf files…

    I was hoping not to use this approach but I’m left with no choice…

    Regards,

    Hala[/activereports_archive]

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels