<< Click to Display Table of Contents >> Navigation: Component Description > Methods > TWPViewPDF.AddDrawObject |
Add graphical objects. Uses the TPDFDrawObjectRec structure and the additional data to prepare a TPDFDrawObjectRec parameter record which is passed to the engine.
procedure AddDrawObject(Mode: TWPAddDrawObjectMode;
Name: WideString;
var Param: TPDFDrawObjectRec;
StrParam: WideString;
data: PAnsiChar = nil;
datalen: Integer = 0); overload;
procedure AddDrawObject(Mode: TWPAddDrawObjectMode;
Name: WideString;
var Param: TPDFDrawObjectRec;
data: TMemoryStream = nil;
StrParam: WideString = ''); overload;
Also see: AddHighlightRect which can be used
in combination with FindText.
Parameters:
var Param: TPDFDrawObjectRec;
type TPDFDrawObjectRec=
packed record
PageNo : Integer; // Page number to place the object
x,y,w,h : Integer; // 72 dpi, for grtyp>0 ist 720 dpi
ColorBrush : Cardinal; // Background Color
grtyp : Integer; // Graphic type. (Ignore all other props if 0 = V2 compatibility mode)
// 0=default highlight (alpha=120)
// 1=rectangle
// 2=circle
// 3=ellipse
// 20= Image
// 100= Text
structsize : Integer; // Size of this structure.
typparam : Integer; // Extra Parameters for this type
// For Images it is the Image ID
units_xywh: Integer; // 0 and 1=72 dpi, divisor
// -------
Alpha : Integer; // 0 or Alpha in range 1..255.
// Use ColorBrush=clNone (=$1FFFFFFF) to draw transparently
Angle : Integer; // 0..360
ColorPen : Cardinal; // Line Color
ColorText : Cardinal; // Textcolor, forground
FontSize : Integer; // For Texts it is the font size in point multiplied by 100
PenWidth : Integer; // Line Width in pt * 1000, 0 does not paint a line
ObjectOptions : Integer; // Option Bitfield
// 1 : Keep AspectRatio
// 2 : Stretch (used for text)
// 4 : Center horizontally (text in the box)
// 8 : Used for Text and JPEG. Draw Background in selected Brush Color and Pen
// 16 : Apply Brush Color after painting the object
// 32 : prohibit moving the object
// 64 : prohibit changing size of object
Padding : Integer; // Padding inside - using 720dpi
HRad, VRad : Integer; // Horizontal, Vertical Radius - using 720dpi
PenStyle : Integer; // 4 bytes to define a stroking pattern (reserved)
CreateOptions : Integer; // How should the object be created - Bitfield
// 1 : Place the object UNDER the Page
// 2 : Place at the Right Border of the page (ignore X)
// 4 : Place at the Bottom Border of the page (ignore Y)
// 8 : Scale the object to the page horizontally (uses X as right and left margin)
// 16 : Scale the object to the page vertically (uses Y as right and left margin)
// 32 : Create the object and select it (clear selection)
// 64 : Create the object and add it to the selction (do not clear selection)
// ...
// 8192*2 : Do NOT refresh the screen
// ----
// Offsets to BLOB Data
Fields : Cardinal; // Select fields for the "Get" and "Set" commands
// 1 : PageNo (move to a different page!)
// 2 : X
// 4 : Y
// 8 : W
// 16 : H
// .... OBJFL_....
textoff : Integer; // Offset to the wide char text data (should follow the predefined data)
textlen : Integer; // length of Text
NameOff : Integer; // Offset to name (widechar)
NameLen : Integer; // Length of name
DataOff : Integer; // Offset to the object data. (should follow the predefined data)
Datalen : Integer; // Length of the data.
DataTyp : Integer; // Certain flags to tell what to do with the data
// 1 = ANSI Text
// 2 = Unicode Text
// 3 = JPEG Data ... (reserved ..)
// ... now text and data can follow. Offsets are measured from start of structure.
end;
StrParam: WideString
This parameter can contain various additional properties separated by comma:
"font=x" - select the font x
"size=x" - select the font size x / 100
"text=x" - set the text x
"color=x" - select the color name x
"background=x" - select the background color x
"stretch=x" - if x=1 then stretch the font, otherwise don't stretch
Examples:
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.
Add a text object:
var
t: TPDFDrawObjectRec;
begin
FillChar(t, SizeOf(t), 0);
t.PageNo := 0; // First Page
t.units_xywh := 10; // 720 dpi
//
t.grtyp := 100; //
t.x := Round( 3.2 * 720); // 3.2 inches
t.y := Round( 1.3 * 720); // 1.3 inch down
t.w := Round( label1.Width/96 * 720);
t.h := Round( label1.Height/96 * 720);
WPViewPDF1.AddDrawObject(wpAddNow, '', t,
'This is a sample text',
'"Font=Arial","size=1100"');
end