<< Click to Display Table of Contents >> Navigation: Tasks > Draw Shapes / Text objects on PDF > VCL: Example - highlight rectangle |
Draw a highlighted rectangle at a certain position:
var
t: TPDFDrawObjectRec;
begin
FillChar(t, SizeOf(t), 0);
t.PageNo := 0; // Page 1
t.ColorBrush := clYellow;
t.Alpha := 100; // transparent
t.grtyp := 1; // Rectangle
t.ObjectOptions := 16; // Use multiply transparency
// Position, 720 dpi
t.units_xywh := 10; // 720 dpi
t.x := Round( 2/2.54 * 720); // 2 cm
t.y := Round( 3/2.54 * 720); // 3 cm
t.w := Round( 5/2.54 * 720);
t.h := Round( 1/2.54 * 720);
WPViewPDF1.AddDrawObject(wpAddNow, 'YELLOW_RECT', t, nil, '');
end;
Move that rectangle to a different position:
var
t: TPDFDrawObjectRec; pw : Double;
begin
FillChar(t, SizeOf(t), 0);
t.PageNo := 0; // Page 1
t.units_xywh := 10; // 720 dpi
t.x := Round( Random(10)/2.54 * 720); // move somewhere
t.y := Round( Random(10)/2.54 * 720); //
t.w := Round( 5/2.54 * 720);
t.h := Round( 1/2.54 * 720);
t.Fields := OBJFL_X + OBJFL_Y + OBJFL_W + OBJFL_H;
WPViewPDF1.AddDrawObject(wpModifyExistingObj, 'YELLOW_RECT', t, nil, '');
end;
Note: If you use wpMoveExistingObj instead of wpModifyExistingObj the values of X,Y,W,H and PageNo are added to the current values of this properties.