<< Click to Display Table of Contents >> Navigation: Create a PDF Editor > Delphi Example > Add all buttons to the tool bar |
The buttons are created on the TToolbar at runtime. A list of action names is used select the actions to be used.
The position of the action in the list is expected to be the image index in the TImageList.
This is the list of actions:
const _ActionButtons ='FileOpen,FileAppend,FileSaveAsPDF,SelectStd,SelectObjects,ZoomToRect,SelectText,' +
'SelectFillForm,DrawFieldEdit,DrawFieldCheck,DrawAnnotFrame,DrawAnnotHighlight,DrawAnnotFreetext,' +
'DrawAnnotSymbol,DrawAnnotSquiggly,DrawAnnotHighlightText,DrawAnnotBlackText,' +
'DrawTextline,DrawRect,DrawImage,DrawHighlight,DrawCircle,About';
We also a TImageList with the buttons.
We use this glyphs:
Note: WPViewPDf Standard does not support the creation of fields, checkboxes and popups. The other annotations and draw objects can be created and printed, but it is not possible to save them.
The procedure InitToolbar creates all buttons. It expects the actions to use the prefix act in their names.
procedure TForm2.InitToolbar;
var NotFound : String;
function Find(aName : String ) : TAction;
var i : Integer;
begin
for i := 0 to ActionList1.ActionCount-1 do
if SameStr( ActionList1.Actions[i].Name, 'act' + aName) then
begin
Result := ActionList1.Actions[i] as TAction;
exit;
end;
Result := nil;
if NotFound<>'' then NotFound := NotFound + ', ';
NotFound := NotFound + aName;
end;
var str : TStringList; i : Integer; btn :TToolButton;
action : TAction;
begin
str := TStringList.Create;
NotFound := '';
try
str.Sorted := false;
str.CommaText := _ActionButtons;
ToolBar1.Images := ImageList1;
ToolBar1.ButtonHeight := ToolBar1.Images.Width;
ToolBar1.ButtonWidth := ToolBar1.Images.Height;
ToolBar1.Height := ToolBar1.ButtonHeight + 4;
// create all buttons from our action list
for I := str.Count-1 downto 0 do
begin
action := Find(str[i]);
if action<>nil then
begin
btn := TToolButton.Create(ToolBar1);
btn.ShowHint := true;
btn.Width := ToolBar1.Images.Width;
btn.Height := ToolBar1.Images.Height;
btn.Parent := ToolBar1;
action.ImageIndex := i;
btn.ImageIndex := i;
btn.Action := action;
end;
end;
// For debug reasons
if NotFound<>'' then
ShowMessage('This WPViewPDF actions were not found' + #13 + NotFound);
finally
str.Free;
end;
end;