PDFiumVCL Docs

InsertFormObjectFromXObject method

Dieser API-Eintrag behält Bezeichner, Signaturen, Codeblöcke und PDF-Begriffe in ihrer Originalform.
Component: TPdf  ·  Unit: PDFium
Inserts ONE copy of the page wrapped by a TPdfXObject into the current page of this document, returning the FPDF_PAGEOBJECT so the caller can position / scale / rotate it.

Syntax

function InsertFormObjectFromXObject(XObject: TPdfXObject): FPDF_PAGEOBJECT;

Description

InsertFormObjectFromXObject is the second half of the v1.25.0 Form XObject reuse API. It takes a TPdfXObject handle (built by CreateXObjectFromPage) and inserts ONE FPDF_PAGEOBJECT that references that XObject into THIS document's CURRENT page. Each call inserts a new page object, so the same XObject can be stamped multiple times across multiple pages of the destination — every stamp shares the underlying page-content cache, which keeps file size down even when the watermark / template is busy.

The returned FPDF_PAGEOBJECT handle lets the caller call FPDFPageObj_SetMatrix or the TPdfMatrix helpers to position / scale / rotate the stamp anywhere on the page. Without an explicit transform the inserted page sits at the bottom-left corner at 1:1 scale, which is almost never what you want; always set a matrix before calling UpdatePage.

Returns nil on failure (XObject is nil, this TPdf not Active, no current page). After insertion the page object is owned by the page, not by the XObject — freeing the XObject does not invalidate the inserted page object.

Remarks

Example

uses FPdfMatrix;

var
  PageObj: FPDF_PAGEOBJECT;
  M: TPdfMatrix;
begin
  Pdf1.PageNumber := 3;
  PageObj := Pdf1.InsertFormObjectFromXObject(XObj);
  if PageObj <> nil then
  begin
    M := TPdfMatrix.Create;
    try
      M.Translate(100, 200);
      M.Scale(0.5, 0.5);
      M.Rotate(15);
      FPDFPageObj_SetMatrix(PageObj, M.AsMatrix);
    finally
      M.Free;
    end;
    Pdf1.UpdatePage;
  end;
end;

See Also

CreateXObjectFromPage, UpdatePage, PageNumber