-
Notifications
You must be signed in to change notification settings - Fork 1
2.19 Memory Control
As a document is being built, the PDF File Writer accumulates all the information required to create the PDF file. The information is kept in memory except for images and embedded files. Images and embedded files are automatically written to the output file when they are declared. For very large documents the memory used keeps growing. The library offers methods (CommitToPdfFile
) to write contents information to the output file and invoke the garbage collector to free the unused memory. The GC.Collect
method takes time to execute. If execution time is an issue, set the GCCollect
argument once every few pages. In other words, the CommitToPdfFile
must run for every page but the cleanup is done once every few pages. Once a commit was executed, no additional information can be added. PdfTable
automatically starts a new page when the next row cannot fit at the bottom of the current page. The PdfTable
class has two members CommitToPdfFile
and CommitGCCollectFreq
to control memory usage while a table is being build. The PdfChart
class generates an image from the .NET Chart class. The DrawChart
method of PdfContents
will perform the commit. Alternatively, you can call CommitToPdfFile
method of PdfChart
.
// PdfContents, PdfXObject and PdfTilingPattern
// Commit the contents to output file.
// Once committed, this PdfContents cannot be used.
// The argument is GCCollect
Contents.CommitToPdfFile(true);
This page is a copy from https://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library by Uzi Granot. The article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL). All rights to the texts and source code remain with Uzi Granot.