TL;DR: The new built-in toolbar feature added to the Syncfusion .NET MAUI PDF Viewer saves users time and provides a seamless user experience with essential functions such as page navigation, text search, and more. This blog explores the built-in toolbar and its advanced customization options in the PDF Viewer to suit our specific needs.
With the growing popularity of .NET MAUI among developers, there is an increasing demand for robust PDF viewing and editing tools. One notable component that meets these needs is the Syncfusion .NET MAUI PDF Viewer, which recently introduced built-in toolbar support in the Essential Studio® 2024 volume 2 release. This feature is available on both mobile and desktop platforms.
Previously, developers had to write extensive code to create their toolbar and tools from the application level, but now, the built-in toolbar significantly reduces this effort.
Let’s explore the various tools and customization options available in the .NET MAUI PDF Viewer’s built-in toolbar for better PDF viewing and editing capabilities.
Let’s explore the tools available in the built-in toolbar for search, navigation, viewing, annotations, and printing functionalities.
Note: The appearance, visibility, positioning, and user experience of specific tools in the toolbar may vary between mobile and desktop platforms. This variation is based on usability considerations and available screen space, ensuring optimal functionality for each platform.
Depending on the available screen space, the .NET MAUI PDF Viewer organizes its tools into multiple or multilevel toolbars on mobile and desktop platforms.
For example, view options, navigation tools, search, and print options are available in the primary or top toolbar. In contrast, annotation tools are available in the secondary or bottom toolbar, and so on. Users need to access specific toolbars to access the corresponding toolbar items.
Let’s see how to customize and access toolbars and their items using code-behind APIs.
In specific scenarios, you should hide all the toolbars in the .NET MAUI PDF Viewer to display the document in full-view mode or use customized toolbars based on your app needs. You can hide all toolbars by setting the ShowToolbars property to False. Refer to the following code example.
XAML
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="PdfViewerDemo.MainPage" xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"> <syncfusion:SfPdfViewer x:Name="PdfViewer" ShowToolbars="False"/> </ContentPage>
C#
SfPdfViewer PdfViewer = new SfPdfViewer(); PdfViewer.ShowToolbars = false;
Note: For more details, refer to the GitHub demo for hiding the toolbar in the .NET MAUI PDF Viewer.
Sometimes, you might need to hide specific toolbars instead of all. This can be useful if you want to simplify the user interface by removing unnecessary tools or creating a more focused environment for certain tasks. The Toolbars collection property in the PDF Viewer allows us to hide a specific toolbar by using its index or name.
Let’s see them in detail!
If you know the position of the toolbar you want to hide within the Toolbars collection, you can access and hide it using its index. For example, you can use the following code to hide the first and second toolbars in the collection.
C#
if (PdfViewer.Toolbars.Count > 1) { PdfViewer.Toolbars[0].IsVisible = false; PdfViewer.Toolbars[1].IsVisible = false; }
In scenarios where you need to hide toolbars based on their specific functionality, using their names is more practical and flexible. This can be achieved by passing the toolbar’s name to the GetByName method for toolbar collection.
For example, you can use the following code to hide the bottom toolbar in the PDF Viewer, which contains annotation tools on the mobile platform.
C#
// Get the bottom toolbar in the PDF Viewer that contains annotation tools on mobile platforms. Syncfusion.Maui.PdfViewer.Toolbar? bottomToolbar = PdfViewer.Toolbars?.GetByName("BottomToolbar"); if (bottomToolbar != null) { // Hide the toolbar. bottomToolbar.IsVisible = false; }
To find the names and purposes of other toolbars, you can refer to this documentation.
Alternatively, you can identify a toolbar’s name using its Name property within the Toolbar object. Refer to the following code to find the name of the first toolbar.
C#
if (PdfViewer.Toolbars != null && PdfViewer.Toolbars.Count > 0) { // Get the name of the first toolbar. string name = PdfViewer.Toolbars[0].Name; }
In addition to customizing the visibility of toolbars, you can customize the items within each toolbar of the .NET MAUI PDF Viewer. This includes adding new items, removing existing ones, or rearranging their order to suit your app’s workflow better.
To add new items to a toolbar, we can use the Items collection of the Toolbar object. Here’s an example of converting a button to a ToolbarItem object and adding it to the top toolbar.
C#
/// <summary> /// Add a save button to the PDF Viewer toolbar. /// </summary> void AddSaveDocumentButton() { Button saveDocumentButton = new Button { Text = "Save", Padding = 10 }; saveDocumentButton.Clicked += SaveDocumentClicked; // Create toolbar item. Syncfusion.Maui.PdfViewer.ToolbarItem toolbarItem = new Syncfusion.Maui.PdfViewer.ToolbarItem(saveDocumentButton, "SaveDocumentButton"); // Get the top toolbar of the PDF Viewer that contains primary tools on mobile platforms. Syncfusion.Maui.PdfViewer.Toolbar? topToolbar = PdfViewer.Toolbars?.GetByName("TopToolbar"); if (topToolbar != null) { // Add the save button to the toolbar. topToolbar?.Items?.Add(toolbarItem); } } private void SaveDocumentClicked(object? sender, EventArgs e) { // Write your logic to save the document. }
Refer to the following image.
If you need to remove specific items from a toolbar, you can do so from the Items collection. You can remove them either by index or by name.
Removing an item by its index is straightforward. Here’s how to remove an item from the top toolbar at a specific index.
C#
// Get the top toolbar of the PDF Viewer that contains annotation tools on mobile platforms. Syncfusion.Maui.PdfViewer.Toolbar? topToolbar = PdfViewer.Toolbars?.GetByName("TopToolbar"); if (topToolbar != null) { // Get the first item from the toolbar. Syncfusion.Maui.PdfViewer.ToolbarItem? firstItem = topToolbar.Items?[0]; if (firstItem != null) { // Remove the first item from the toolbar. topToolbar?.Items?.Remove(firstItem); } }
Removing an item by its name provides a targeted approach, particularly useful when managing named items within the toolbar. Here’s how to remove the outlines tool from the primary toolbar on desktop platforms using its name.
// Get the primary toolbar of the PDF Viewer that contains primary tools on desktop platforms. Syncfusion.Maui.PdfViewer.Toolbar? primaryToolbar = PdfViewer.Toolbars?.GetByName("PrimaryToolbar"); if (primaryToolbar != null) { // Get the outline from the toolbar. Syncfusion.Maui.PdfViewer.ToolbarItem? outlineTool = primaryToolbar.Items?.GetByName("Outline"); ; if (outlineTool != null) { // Remove the tool from the toolbar. primaryToolbar?.Items?.Remove(outlineTool); } }
Refer to the following images.
To find the names and details of other toolbar items, you can refer to this documentation. Alternatively, you can identify an item’s name using its Name property.
Note: For more details, refer to removing toolbar items in the .NET MAUI PDF Viewer GitHub demo.
Thanks for reading! In this blog, we’ve explored the new built-in tollbar feature added to the Syncfusion .NET MAUI PDF Viewer and its customization options in detail. This feature is available in our 2024 volume 2 release. With this user-friendly update, you can provide seamless PDF viewing and editing capabilities in your apps!
You can check out all the other features in this Volume 2 release on our Release Notes and What’s New pages.
You can also download and check out our Syncfusion .NET MAUI demo app from Google Play and the Microsoft Store.
The existing customers can download the new version of Essential Studio® on the License and Downloads page. If you are not a Syncfusion customer, try our 30-day free trial to check out our incredible features.
You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!