Skip to content

2.19 Memory Control

OgreTransporter edited this page Mar 2, 2020 · 1 revision

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);
Clone this wiki locally