Delete and modify shapes

<< Click to Display Table of Contents >>

Navigation:  Tasks > Draw Shapes / Text objects on PDF >

Delete and modify shapes

The shapes can be removed with the command COMPDF_ClearDrawObjects  = 519.

 

The API ClearDrawObject can also be used, it wraps this command:

 

procedure TWPViewPDF.ClearDrawObject(PageNo  : Integer = -1; typselect : Integer = -1);

begin

   CommandStrEx(COMPDF_ClearDrawObjects, IntToStr(typselect), Cardinal(PageNo));

end;

 

The parameters are:

 PageNo : the page number, -1 for all

 typselect : what should be selected. Any positive number deletes only the objects of a certain grtyp.

    -1 delete  all,

    -2 delete only the selected.

 

 

You can also use the overloaded method and pass the name of the shape to be deleted. It will be found on all pages if PageNo is -1.

 

 

It is possible to modify a shape using AddDrawObject( wpModifyExistingObj, .. )

 

To use this method set in the TPDFDrawObjectRec record all parameters You need to change. Then add a bit for each element which should be changed to the element Fields.

 

VCL Example:

 

var

  t: TPDFDrawObjectRec;

begin

  FillChar(t, SizeOf(t), 0);

  t.PageNo := 0; // First Page 

  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, 'SHAPE_NAME', t, nil, ''); 

end;

 

 

It is also possible to move an object to a different page.

 

If you need to move an object to a position in relation to its current position use wpMoveExistingObj instead of wpModifyExistingObj.

 

 

You can use COMPDF_DrawObjectLocateAtXY to check for an object at a certain mouse X,Y position and COMPDF_DrawObjectReadProp to retrieve its position in points.

 

procedure TMetafileOverlay.FormMouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

begin

   StatusBar1.SimpleText := '-' +

      WPViewPDF1.CommandGetStr(COMPDF_DrawObjectLocateAtXY, '', Cardinal(-1)) +

      '@' +

      IntToStr( WPViewPDF1.Command(COMPDF_DrawObjectReadProp, 1) )  + ',' +

      IntToStr( WPViewPDF1.Command(COMPDF_DrawObjectReadProp, 2) );

end;