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.