PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Big file generation
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3709
Page 1 of 1

Author:  panayot.p [ Thu Jan 11, 2018 4:59 pm ]
Post subject:  Big file generation

Hi, This is my first project using MigraDoc.
I need to generate a large pdf file with a huge table. The table might have up to 2 million records. Is there a way to do that?
Currently I am getting out of memory exception long before I add all rows to the table.
I am not attaching any code because at that point it is just a simplified version of the Invoice-sample from pdfsharp wiki.

I have a second question. I don't see a dispose method on MigraDoc.DocumentObjectModel.Document or MigraDoc.Rendering.PdfDocumentRenderer, how do I go about freeing the memory once I am done rendering?

Author:  TH-Soft [ Thu Jan 11, 2018 8:47 pm ]
Post subject:  Re: Big file generation

Hi!
panayot.p wrote:
I need to generate a large pdf file with a huge table. The table might have up to 2 million records. Is there a way to do that?
I don't know.
Make sure your app is running in 64 bit mode. Apps in 32 bit mode are limited to 2 GiB of RAM - even on computers with 32 or 64 GiB of RAM.


panayot.p wrote:
I don't see a dispose method on MigraDoc.DocumentObjectModel.Document or MigraDoc.Rendering.PdfDocumentRenderer, how do I go about freeing the memory once I am done rendering?
The IDisposable pattern makes sense for classes that use limited resources like file handles.
For POCO classes this is not needed. The Garbage Collector will remove the object when all references are gone.
Just set your variable to "null".

Author:  panayot.p [ Fri Jan 12, 2018 8:34 am ]
Post subject:  Re: Big file generation

Thank you for the fast replay.

I was wondering if this can be done smarter. Maybe by generating a few pages at a time and saving them and then continuing with the next batch instead of trying to render the whole document at once.
With the memory requirements I am seeing while generating a smaller pdf I calculated that I will need around 15 GB even before I call RenderDocument so this is not really viable in my case. I really need some sort of a page by page rendering.

Author:  TH-Soft [ Fri Jan 12, 2018 3:04 pm ]
Post subject:  Re: Big file generation

panayot.p wrote:
I really need some sort of a page by page rendering.
Just do it.
The technique shown in this sample can also be used to create a huge document in small batches:
viewtopic.php?f=8&t=3172
Maybe not do it page by page, but in batches of 20 or 50 pages or so.

You write you have one really huge table. This will make things a bit complicated if table rows have varying heights.
It's simple if all rows have the same height.

You can even close the PDFsharp document from time to time (maybe every 500 pages) to free the PDFsharp memory, too.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/