PDFium Delphi Component Docs

StampPagesFromPdf method

Component: TPdf  ·  Unit: PDFium
Stamps a page from another TPdf as a positioned, scaled, optionally rotated Form XObject overlay or underlay across one or more target pages

Syntax

function StampPagesFromPdf(
  Source : TPdf;
  SourcePageIndex : Integer;
  const TargetPages : array of Integer;
  const Options : TPdfOverlayOptions;
  out Report : TPdfOverlayReport): Boolean;

Description

StampPagesFromPdf is the high-level overlay, underlay, and watermark composer. It manufactures a Form XObject from a source page through FPDF_NewXObjectFromPage, then drops one positioned, scaled, optionally rotated copy of that XObject into each requested target page. Placement, scaling, rotation, blend mode, and z-order are controlled through the TPdfOverlayOptions record (Placement, X, Y, Scale, Rotation, Margin, UseCropBox, ZUnderlay, and BlendMode); the TPdfOverlayReport out parameter records StampedPageCount, FailedPageCount, SkippedPageCount, SourcePageWidth, SourcePageHeight, Succeeded, and ErrorMessage

Internally each stamp combines FPDF_NewFormObjectFromXObject, FPDFPageObj_SetMatrix, FPDFPageObj_SetBlendMode, and either FPDFPage_InsertObject (overlay) or FPDFPage_InsertObjectAtIndex with stack index 0 (underlay). The placement matrix is built from PageWidth/PageHeight plus the option fields, so all anchors, margins, scaling, and rotation map to a single transform that PDFium applies to the inserted form object

Source and destination must both be Active. The source may be a separate TPdf instance or even THIS document (self-stamp): the caller's current PageNumber on both documents is saved and restored across the call

Parameters

Remarks

Example

var
  Watermark: TPdf;
  Options: TPdfOverlayOptions;
  Report: TPdfOverlayReport;
begin
  Watermark := TPdf.Create(nil);
  try
    Watermark.FileName := 'C:\Confidential.pdf';
    Watermark.Active := True;
    Options := TPdfOverlayOptions.Default;
    Options.Placement := opCenter;
    Options.Rotation := 45;
    Options.BlendMode := bmMultiply;
    Pdf1.StampPagesFromPdf(Watermark, 0, [], Options, Report);
  finally
    Watermark.Free;
  end;
end;

See Also

CreateXObjectFromPage, InsertFormObjectFromXObject, TransformPageObject, ImportPagesByIndex