CompactDocumentMemory

Memory management, temporary files, performance

Description

Re-encodes the selected document and moves large serialized indirect objects into the temporary file configured by SetTempFile

Syntax

Delphi

Function TPDFlib.CompactDocumentMemory: Integer;

Return values

1The document was compacted successfully
0No temporary file was configured or an object could not be materialized or serialized

Remarks

Call SetTempFile before this method and optionally use SetTempFileQuota to bound disk use

Spool entries are indexed by object number and generation for logarithmic lookup and remain readable after the write handle closes

If the quota is reached, affected objects remain in memory and the method can still succeed

The decoded objects are released, so the page tree and the form are read again afterwards. The selected page, the selected font and the text size are kept; other settings that belong to the drawing state of that page, such as the selected layer, start afresh as they do after SelectPage

Fonts, images, graphics states, colour spaces, shaders, patterns, captured pages, outlines, optional content groups and destinations created or selected before the call can be used after it with the same IDs. The objects that make up the fonts of the document, and the objects such IDs name, stay in memory; image data is written out with everything else and read back when the image is next used

An ID that names a part of another object — the action or the destination read from an annotation or an outline, the measurement dictionary of an image — keeps naming the copy that existed before the call. A change made through it afterwards does not reach the document, so read such an ID again after compacting