PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 13, 2024 3:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Dec 23, 2014 2:53 am 
Offline

Joined: Tue Dec 23, 2014 2:41 am
Posts: 1
New user to MigraDoc (and PDF generation in general), like the library very much so far. I am going to use it to generate 5000-20000 single-page PDFs at a time, put them into a zip file, and allow users to export many customers. Fun! I am currently trying to create 10000 PDFs, as a test case and learning experience, using the Invoice sample application (the GDI+ C# one). I have basically just said "use the normal Invoice class and loop a lot of times":

Code:
using (var stream = new MemoryStream())
{
    using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
    {
        for (int i = 0; i < 10000; i++)
        {
            Trace.TraceInformation("Starting {0}", i);
 
            var entry = archive.CreateEntry(string.Format("{0}.pdf", i));
 
            var invoice = new InvoiceForm("../../invoice.xml");
            var document = invoice.CreateDocument();
            var renderer = new PdfDocumentRenderer(true) {Document = document};
            renderer.RenderDocument();
           
            using(var rendererStream = new MemoryStream())
            using (var zipEntryStream = entry.Open())
            {
                renderer.Save(rendererStream, false);
               
                rendererStream.CopyTo(zipEntryStream);
            }
        }
    }
    var bytes = stream.ToArray();
}


I understand that this is not smart and probably recommended only for small collections of files. I run OOM @ around 1000 PDFs created in a ASP.NET application, and around 5000 in a console application (it tries so hard though: http://i.imgur.com/Q37l3Z9.png).

Can I get any more mileage out of this approach, or should I just stop now and create all the files locally one by one and zip normally? Is there any way to pre-compile/render/template the document so that I could create a simple instance of it, replacing only 1-2 fields of custom data (like the address fields in the invoice sample but not the overall layout)? Not sure if that is the right terminology.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 12, 2015 9:39 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Hi!

The image shows 406 MB total memory and 328 MB large object heap. Is that the point when the application crashes?

32 bit applications should be able to handle up to 2000 MB memory and 64 bit applications should handle even more.

Since .NET 4.5.1 you can invoke a garbage collection for the large object heap. This might take you a bit further:
http://msdn.microsoft.com/en-us/magazine/cc534993.aspx

But IMHO it's probably better to save the PDF files to disk and then combine them.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 84 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group