Skip to content

TTMSFNCWXPDFToolbar

The TTMSFNCWXPDFToolbar is a companion component to TTMSFNCWXPDFViewer. It provides a row of icon buttons for common PDF viewer actions: opening a file, navigating pages, zooming, and rotating. Assign the viewer to the Viewer property and the toolbar wires itself up automatically. Custom buttons with arbitrary click handlers can be added alongside the built-in ones.

Getting started

Drop a TTMSFNCWXPDFViewer and a TTMSFNCWXPDFToolbar on the form. Assign the viewer at runtime (or design time via the Object Inspector):

procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFNCWXPDFToolbar1.Viewer := TMSFNCWXPDFViewer1;
end;

The toolbar starts with 9 built-in buttons. All buttons are initially disabled; they become enabled automatically when a PDF is loaded. Navigation buttons (First Page, Previous Page, Next Page, Last Page) are intelligently enabled or disabled depending on the current page.

Default buttons

The toolbar adds these 9 buttons in order when it is first created:

Position Role Action
1 trOpenFile Opens a file picker and loads the selected PDF.
2 trFirstPage Navigates to page 1.
3 trPreviousPage Navigates to the previous page.
4 trNextPage Navigates to the next page.
5 trLastPage Navigates to the last page.
6 trZoomOut Decreases the zoom level.
7 trZoomIn Increases the zoom level.
8 trRotateLeft Rotates the view 90° counter-clockwise.
9 trRotateRight Rotates the view 90° clockwise.

Each button displays a built-in SVG icon. You can replace the icon by assigning a TTMSFNCBitmap to the item's Bitmap property.

TTMSFNCWXPDFToolbarItemRole values

Value Description
trOpenFile Opens a file dialog to select and load a PDF. On WEB, uses a browser file picker.
trFirstPage Calls Viewer.ShowPage(1). Disabled when already on page 1.
trPreviousPage Calls Viewer.PreviousPage. Disabled when already on page 1.
trNextPage Calls Viewer.NextPage. Disabled when already on the last page.
trLastPage Calls Viewer.ShowPage(Viewer.PageCount). Disabled when already on the last page.
trZoomIn Calls Viewer.ZoomIn.
trZoomOut Calls Viewer.ZoomOut.
trRotateLeft Calls Viewer.TurnAngleLeft.
trRotateRight Calls Viewer.TurnAngleRight.
trCustom A user-defined button. Fires OnCustomEvent when clicked.

Adding a custom button

Set PDFRole to trCustom and assign an OnCustomEvent handler:

procedure TForm1.DoMyAction(Sender: TObject);
begin
  ShowMessage('Custom toolbar button clicked!');
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  itm: TTMSFNCWXPDFToolbarItem;
begin
  TMSFNCWXPDFToolbar1.Viewer := TMSFNCWXPDFViewer1;

  itm := TMSFNCWXPDFToolbar1.Items.Add;
  itm.PDFRole := trCustom;
  itm.OnCustomEvent := DoMyAction;

  // Optionally provide a custom icon:
  // itm.Bitmap := TTMSFNCBitmap.CreateFromResource('MyIcon');
end;

Removing or modifying built-in buttons

Access buttons through the Items collection. Items are ordered by their position in the toolbar:

procedure TForm1.RemoveOpenButton;
var
  I: Integer;
begin
  // Find and remove the Open File button
  for I := TMSFNCWXPDFToolbar1.Items.Count - 1 downto 0 do
  begin
    if TMSFNCWXPDFToolbar1.Items[I].PDFRole = trOpenFile then
    begin
      TMSFNCWXPDFToolbar1.Items.Delete(I);
      Break;
    end;
  end;
end;

Orientation

The toolbar can be laid out horizontally (default for a top/bottom toolbar) or vertically (for a side panel):

TMSFNCWXPDFToolbar1.Orientation := toHorizontal;  // default
TMSFNCWXPDFToolbar1.Orientation := toVertical;

The default component size is 500 × 40 pixels, suitable for a horizontal toolbar across the top or bottom of a viewer.

Properties

Property Type Description
AntiAliasing Boolean Enables anti-aliased rendering of button icons.
Appearance TTMSFNCCustomListAppearance Visual settings for button items (colours, fonts, item width).
Items TTMSFNCWXPDFToolbarItems Collection of TTMSFNCWXPDFToolbarItem objects. Populated with 9 default items at creation.
Orientation TTMSFNCCustomListOrientation Layout direction: toHorizontal or toVertical.
Version string Read-only. Component version string.
Viewer TTMSFNCWXPDFViewer The linked PDF viewer. Assigning this wires up automatic page state management.

TTMSFNCWXPDFToolbarItem properties

Property Type Default Description
Bitmap TTMSFNCBitmap Custom icon for this button. When empty the built-in SVG icon for the role is used.
HorizontalTextAlign TTMSFNCGraphicsTextAlign Horizontal alignment of the button label text.
OnCustomEvent TNotifyEvent Callback invoked when a trCustom button is clicked. The Sender is the toolbar item itself.
PDFRole TTMSFNCWXPDFToolbarItemRole trOpenFile The action this button performs. See the role table above.
Text string Optional text label displayed on the button.
VerticalTextAlign TTMSFNCGraphicsTextAlign Vertical alignment of the button label text.

Events

Event Description
OnAfterDraw Fires after the entire toolbar is drawn.
OnBeforeDraw Fires before the entire toolbar is drawn.
OnItemAfterDrawBackground Fires after the background of each button is drawn.
OnItemAfterDrawContent Fires after the icon of each button is drawn.
OnItemAfterDrawText Fires after the text label of each button is drawn.
OnItemBeforeDrawBackground Fires before the background of each button is drawn.
OnItemBeforeDrawContent Fires before the icon of each button is drawn.
OnItemBeforeDrawText Fires before the text label of each button is drawn.
OnItemClick Fires when the user clicks any button. Receives the 0-based item index.
OnItemSelected Fires when a button item becomes selected.