<< Click to Display Table of Contents >> Navigation: Tasks > Draw Shapes / Text objects on PDF > VCL: Add text draw object to all pages |
The code below is the central part of this Delphi Demo:
var
WPPDF: TWPViewPDF;
T: TPDFDrawObjectRec;
cnt, FTransparencyPercent, FRotationAngle : Integer;
....
// loop through all pages of the PDF
for cnt := 0 to WPPDF.PageCount-1 do
begin
FillChar(T, SizeOf(T), 0);
T.structsize := SizeOf(T); //!!
T.PageNo := cnt;
if DrawRect.Checked then
begin
T.grtyp := 0;
T.ColorBrush := clGreen;
end else
begin
T.grtyp := 100;
T.ColorText := clRed;
end;
T.Alpha := Round(FTransparencyPercent / 100 * 255);
T.Angle := FRotationAngle;
T.ObjectOptions := 64;
T.FontSize := StrToIntDef(FontSize.Text,0)*100;
// The offset mode is under development:
T.CreateOptions :=
PDFDrawObjectRecPositionArray[PositionMode.ItemIndex]
+ 2048; // W and H = %
T.units_xywh := 10; // 720 dpi
T.x := StrToIntDef( XOFF.Text, 0);
T.y := StrToIntDef( YOFF.Text, 0);
if T.FontSize=0 then
begin
T.w := StrToIntDef( WPZ.Text, 0); // % due to flag 2048 in CreateOptions
T.h := StrToIntDef( HPZ.Text, 0);
end;
OptionStr := 'FONT=TimesNewRoman'; // alternative: CourierNew';
WPPDF.AddDrawObject(wpAddNow, WideString('TEXTOBJECT'),
T, WideString(FWatermarkText)
, PAnsiChar(OptionStr), Length(OptionStr)
);
end;