PDFiumVCL Docs

RemoveObject method

Ten wpis API zachowuje identyfikatory, sygnatury, bloki kodu i terminy PDF w oryginalnej postaci.
Component: TPdf  ·  Unit: PDFium
Removes the specified page object from the current page. When DestroyObject is True, the removed object is released after removal. The page content stream is regenerated automatically.

Syntax

procedure RemoveObject(Index: Integer; DestroyObject: Boolean = True);

IndexInteger. Zero-based index of the page object to remove (0 to ObjectCount - 1).
DestroyObjectBoolean. When True (default), the underlying PDFium object is freed after removal. Pass False to detach the object from the page without releasing its memory, for example when transferring it to another page.

Description

RemoveObject deletes a page object from the current page by its zero-based index. Valid index values range from 0 to ObjectCount - 1. After the call, the page content stream is regenerated automatically so the change is reflected immediately.

When DestroyObject is True (the default), the underlying PDFium object handle is released and its memory freed. When False, the object is merely detached from the page without being destroyed — this is useful when moving an object from one page to another, where the caller takes ownership of the handle.

Because removing an object shifts the indices of all subsequent objects, take care when removing multiple objects in a loop: iterate from the highest index downward, or collect the indices to remove before starting the loop.

Example

// Remove the last page object
if Pdf1.ObjectCount > 0 then
  Pdf1.RemoveObject(Pdf1.ObjectCount - 1);

// Remove all objects from highest index downward
var I: Integer;
begin
  for I := Pdf1.ObjectCount - 1 downto 0 do
    Pdf1.RemoveObject(I);
end;

See Also

ObjectCount, ObjectType, AddPath