PDFium Component Docs

RemoveObject 메서드

컴포넌트: TPdf  ·  유닛: PDFium
현재 페이지에서 지정한 page object를 제거합니다. DestroyObjectTrue이면 제거된 object는 제거 후 해제됩니다. page content stream은 자동으로 다시 생성됩니다

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