Skip to content

Using controllers in addons ​

API overview ​

Controllers in the SDK are documented under Modules > UIExtension > controllers in the API reference. Controllers defined in addons are listed under Modules > UIExtension > controllers > UIXAddon.

Controllers ​

This section covers:

Tip: See reusable addon controllers for a list of controllers you can reuse from addons.

Use controllers in templates ​

The page-editor:AddTextController example shows how to wire a controller in a template.

During initialization ​

javascript
new PDFUI({
    fragments: [{
        / The target element to be manipulated
        target: 'add-text',
        / The type of operation, here is replacement
        action: UIExtension.UIConsts.FRAGMENT_ACTION.REPLACE,
        / Template,here the "@require-modules" directive is used to handle lazy loading   
        template: `<ribbon-button @controller="page-editor:AddTextController" @require-modules="page-editor"></ribbon-button>`,
    }]
});

Or:

javascript
new PDFUI({
    fragments: [{
        / The target element to be manipulated
        target: 'add-text',
        / The type of operation, here is replacement
        action: UIExtension.UIConsts.FRAGMENT_ACTION.REPLACE,
        / Template,here the "@async" directive is used to handle lazy loading  
        templage: `<ribbon-button @controller="page-editor:AddTextController" @async></ribbon-button>`,
    }]
});

After initialization ​

javascript
// After initialization, use the "Component.after" method to add elements after the component
var someComponent = await pdfui.getComponentByName('some-component-name');
someComponent.after(`<ribbon-button @controller="page-editor:AddTextController"></ribbon-button>`);

Use controllers in fragment configuration ​

The AddImageController example shows configuration-based usage:

javascript
new PDFUI({
    fragments: [{
        / The target element to be manipulated
        target: 'image-tool',
        config: {
            / Specify the controller
            callback: UIExtension.controllers.AddImageController
        }
    }]
});

Limits when using controllers in addons ​

  1. Addon controllers cannot be used via fragment config.callback—only via templates. Addons load asynchronously, so their controllers are not available when fragment config is applied. Templates render after addons load.

  2. Addon controllers are not exposed on UIExtension.controllers.SomeController for the same reason—they are not registered on UIExtension.controllers at startup.