<< Click to Display Table of Contents >> Navigation: Example Projects > Delphi: Add graphics to PDF |
The demo MetaOverlay let You try out the graphic objects. You can add text, rectangle and circle objects.
With WPViewPDF PLUS you can save the data and the objects will be permanently added to the PDF.
This code is executed when the button is pressed:
procedure TMetafileOverlay.DrawRectClick(Sender: TObject);
var
t: TPDFDrawObjectRec;
begin
FillChar(t, SizeOf(t), 0);
t.ColorBrush := clRed;
t.Alpha := 100; // transparent
t.grtyp := 1; // Rectangle
ShowMyHint;
WPViewPDF1.CommandStrEx(COMPDF_MouseAddOneDrawObject,
'REDRECT', Cardinal(@t));
end;
It is also possible to create an object a specific position and to modify its properties after the object was created. The buttons "Create Highlight" and "Move Highlight" showcase this possibility:
// Create an object
procedure TMetafileOverlay.CreateHighlightClick(Sender: TObject);
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
// 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', t, nil, '');
end;
// and move it
procedure TMetafileOverlay.MoveHightlightClick(Sender: TObject);
var
t: TPDFDrawObjectRec;
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 somwhere
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', t, nil, ''); //not: wpMoveExistingObj
end;