Interface: CustomUIConfiguration

PSPDFKit.CustomUIConfiguration

This object can contain callback functions ("renderers") used to customize the appearance of different built-in UI elements.

The UI element to which the callback corresponds is determined by its key or keys. For example, a callback function used to customize the annotations sidebar should be located under PSPDFKit.Configuration.customUI[PSPDFKit.UIElement.Sidebar][PSPDFKit.SidebarMode.ANNOTATIONS].

Currently only the Sidebar Element can be customized, using the PSPDFKit.UIElement.Sidebar key.

Example

//Fully customized sidebar

PSPDFKit.load({
  customUI: {
    [PSPDFKit.UIElement.Sidebar]: {
      [PSPDFKit.SidebarMode.CUSTOM]({ containerNode }) {
        // ReactDOM.createPortal() can be used as well.
        // Or Vue portals, or any other framework API that allows appending components
        // to arbitrary DOM nodes.
        // Using vanilla JS, you can just append a node to parentNode.
        const div = document.createElement("div");
        div.append("My custom sidebar");
        containerNode.appendChild(div);

        return {
          // By returning the same node that was provided, we opt-out of having the node
          // appended. If we return a different node, it will be appended to the provided node.
          node: containerNode,
        };
      }
    }
  }
});

//Partially customized sidebar

PSPDFKit.load({
  customUI: {
    [PSPDFKit.UIElement.Sidebar]: {
      [PSPDFKit.SidebarMode.ANNOTATIONS]({ containerNode }) {
        containerNode.style.padding = "0.5rem";

        if (!containerNode.querySelector(".MyCustomSidebarComponentHeader")) {
          const header = document.createElement("div");
          header.classList.add("MyCustomSidebarComponentHeader");
          containerNode.prepend(header);
        }

        return {
          node: containerNode,
          onRenderItem({ itemContainerNode, item: annotation }) {
            const footerAuthor = itemContainerNode.querySelector(".PSPDFKit-Sidebar-Annotations-Footer span");
            // Change the format of the footer text by prefixing it with "Creator: " and removing the date
            footerAuthor.textContent = `Creator: ${annotation.creatorName}`;

            // Add aria label to the annotation icon
            const annotationIcon = itemContainerNode.querySelector(".PSPDFKit-Icon");
            annotationIcon.setAttribute("aria-label", `Icon for an annotation created by ${annotation.creatorName}.`);
          }
        };
      }
    }
  }
});

Members




Members

sidebarCustomUIConfiguration: PSPDFKit.CustomUIConfiguration.Sidebar

Sidebar custom UI configuration.

Type:
  • PSPDFKit.CustomUIConfiguration.Sidebar
Properties:
Name Type Attributes Description
ANNOTATIONS PSPDFKit.CustomUIRendererCallback <nullable>

Custom UI renderer callback for the annotations sidebar.

THUMBNAILS PSPDFKit.CustomUIRendererCallback <nullable>

Custom UI renderer callback for the thumbnails sidebar.

BOOKMARKS PSPDFKit.CustomUIRendererCallback <nullable>

Custom UI renderer callback for the bookmarks sidebar.

DOCUMENT_OUTLINE PSPDFKit.CustomUIRendererCallback <nullable>

Custom UI renderer callback for the document outline sidebar.

CUSTOM PSPDFKit.CustomUIRendererCallback <nullable>

Custom UI renderer callback for the custom sidebar.


See also