OverlayDocumentPages

Page manipulation, Document assembly

Description

Stamps the pages of another open document onto the pages of the selected document, one source page per target page (letterhead paper, continuous page backgrounds, scanned form templates)

Opacity is clamped to 0 through 1, where 0 is fully transparent and 1 is fully opaque; non-finite opacity returns 0 before importing source pages

Syntax

Delphi

Function TPDFlib.OverlayDocumentPages(SourceDocumentID: Integer; Const TargetPageRange, SourcePageRange: WideString;
  Opacity: Double; Overlay: TPDFlibStampOverlay; Options: Integer): Integer;

Parameters

SourceDocumentIDHandle of the open document supplying the stamp pages. It must not be the selected document
TargetPageRangePages of the selected document to stamp. An empty string selects every page. The k-th selected target page receives the k-th selected source page
SourcePageRangePages of the source document to use, in order. An empty string selects all pages; descending ranges such as 3-1 reverse the source
OpacityStamp opacity from 0.0 to 1.0
OverlaysoOverlay draws above the existing page content; soUnderlay prepends a content layer so the stamp sits underneath it
OptionsBit flags: 1 restart from the first source page when the source runs out (cycle); 2 draw at natural size in the top-left corner instead of the proportional centred fit; 4 keep repeating the last source page; 8 never enlarge the source page beyond its natural size

Return values

0Invalid arguments, or importing the source pages failed; the selected document is unchanged
NThe number of target pages that received a stamp

Remarks

Each source page is imported once and converted into a Form XObject, so stamping a long document with a shared template never duplicates the template resources. By default the stamp is scaled proportionally and centred within the target page's CropBox (falling back to the MediaBox), and pages carrying /Rotate receive an upright stamp fitted to the visual page frame. When the source pages run out before the target pages, the remaining targets stay untouched unless option 1 or 4 selects a continuation rule

Only the visual page content is imported: source annotations, form fields, outlines and structure elements are not merged. This matches the behaviour of the common overlay and multi-stamp command line tools

Example

Letterhead:= PDF.NewDocument;
PDF.LoadFromFile('letterhead.pdf', '');
PDF.SelectDocument(Report);
// repeat the single letterhead page underneath every report page
PDF.OverlayDocumentPages(Letterhead, '', '', 1.0, soUnderlay, 4);

See also

StampText, StampImage, StitchPageOverlay, CollateDocuments