Advanced access to APIs
The APIs for Nutrient MAUI SDK are identical to the APIs for Nutrient Web SDK Standalone. This guide will discuss how to access Nutrient Web SDKs APIs from your MAUI application so that you can take advantage of all the functionalities of our Web SDK.
Preparing a project for advanced access
-
Create a JavaScript asset file and add it to the
Raw/Assets
folder of your project — for example,advanceAccess.js
. -
When initializing
PDFView
in XAML, add the path to the JavaScript asset file to theAdvanceAccessScriptPath
property:
<pspdfkit:PDFView x:Name="PDFView" AdvanceAccessScriptPath="advanceAccess.js" .../>
Accessing APIs
There are two main types of Nutrient Web SDK APIs you can use.
Adding a viewer configuration
To add a configuration that will be used to initialize the viewer, you can add a constant named advanceConfiguration
to the advanceAccess.js
file. For example:
const advanceConfiguration = { enableHistory: true, disableMultiSelection: true, preventTextCopy: true, };
You can find all the configurations available in the configuration
class of the Web SDK here.
Accessing APIs available in the Instance class
To access the APIs available in the Instance
class of Web in standalone mode, first access the object of the Instance
class for the current document using PSPDFKit.Maui.MauiBridge.currentDocument
. Then, for example, if you want to remove the export PDF button from the main toolbar using the setToolbarItems
method, use the following code:
function removeExportButton() { const currentDocument = PSPDFKit.Maui.MauiBridge.currentDocument; const items = currentDocument.toolbarItems; currentDocument.setToolbarItems( items.filter((item) => item.type !== 'export-pdf'), ); }
To call this function from C# on a button click, use the following code:
private async void OnRemoveExportDocumentButtonClicked(object sender, EventArgs e) { await PDFView.Controller.ExecuteJavaScriptFunctionAsync("removeExportButton", new object[] { }); }
You can find an example of advanced access to APIs in our Catalog app’s Advanced API Access example. For additional questions, please get in touch with us.