> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/annotation/annotationmanager/display-authors.md).

# Customize display authors for annotations

Customize display authors for annotations in WebViewer by setting unique IDs as authors instead of usernames. Learn how to map userIds to display names for a user-friendly experience. Export annotatio

When users create annotations in WebViewer, the `Author` property of the annotation is [set](/web/annotation/annotationmanager/permissions.md#default-behavior) to the current user (`Guest` if no user was set). WebViewer enforces annotation permissions by only allowing the current user to edit annotations that have an `Author` value that matches their username.

{% hint style="info" %}
In the XFDF, the \`title\` attribute corresponds to the author of the annotation.
{% endhint %}

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<square page="0" title="John Smith" rect="107.070,480.110,307.900,597.150" name="8b423bdb-5f8c-992f-3dce-3b2dc9a04ffe" subject="Rectangle" color="#E44234" flags="print"/>
```

{% endcode %}
{% endtab %}
{% endtabs %}

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-5a9f5d5ecd687ad341cdde8721d330d9dafcc2f5%2F5dd0225229899045d4e2f4d28f4cd8d5cd591853-294x314.png?alt=media)

Since it's possible that multiple users could have the same username or they may want to change their username in the future, it can be more convenient to set the annotation `Author` to be a unique ID representing the user instead. Otherwise, you would have to update the XFDF data for every annotation created by the user anytime the username changes. However, this would cause the IDs to be shown instead of a friendly name.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<square page="0" title="1" rect="107.070,480.110,307.900,597.150" name="8b423bdb-5f8c-992f-3dce-3b2dc9a04ffe" subject="Rectangle" color="#E44234" flags="print"/>
```

{% endcode %}
{% endtab %}
{% endtabs %}

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-d2e4861a3cd956a66fd96076a210b8bf247a77c4%2F64af8ab4e70b7c5a73bc4db3a26964fabfd10946-292x315.png?alt=media)

In the following example, we will show how to map a `userId` (a unique identifier that won't change after being assigned) to a display name.

## Map a `userId` to a Display Author

Add a mapping function with [setAnnotationDisplayAuthorMap](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#setAnnotationDisplayAuthorMap__anchor) to map the `userId` to a display author, which will be shown as the annotation author name in WebViewer.

{% hint style="warning" %}
For 7.x and below the mapping function takes in an annotation instead of a **userId**.
{% endhint %}

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  annotationUser: '1',
  // other constructor options
}, viewerElement).then(instance => {
  const { annotationManager } = instance.Core;

  annotationManager.setAnnotationDisplayAuthorMap((userId) => {
    if (userId === '1') {
      return 'John Smith';
    } else if (userId === '2') {
      return 'Sally Smith';
    } else {
      return 'Guest';
    }
  });

  annotationManager.setAnnotationDisplayAuthorMap(mapNames);

  // Now you can get a display author by passing in a unique ID
  const displayAuthor = annotationManager.getDisplayAuthor(annotation.Author);
});
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [AnnotationManager.setAnnotationDisplayAuthorMap](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#setAnnotationDisplayAuthorMap__anchor) [AnnotationManager.getDisplayAuthor](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getDisplayAuthor__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  annotationUser: '1',
  // other constructor options
}, viewerElement).then(instance => {
  const { annotManager } = instance;

  annotManager.setAnnotationDisplayAuthorMap((annotation) => {
    const userId = annotation.Author;
    if (userId === '1') {
      return 'John Smith';
    } else if (userId === '2') {
      return 'Sally Smith';
    } else {
      return 'Guest';
    }
  });

  annotManager.setAnnotationDisplayAuthorMap(mapNames);

  // Now you can get a display author by passing in a unique ID
  const displayAuthor = annotManager.getDisplayAuthor(annotation.Author);
});
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [AnnotationManager.setAnnotationDisplayAuthorMap](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#setAnnotationDisplayAuthorMap__anchor) [AnnotationManager.getDisplayAuthor](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getDisplayAuthor__anchor)
{% endtab %}
{% endtabs %}

If you have added a mapping function, it should display those unique IDs as much friendlier names while the ID is still used underneath for permission checking.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<square page="0" title="1" rect="107.070,480.110,307.900,597.150" name="8b423bdb-5f8c-992f-3dce-3b2dc9a04ffe" subject="Rectangle" color="#E44234" flags="print"/>
```

{% endcode %}
{% endtab %}
{% endtabs %}

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-5a9f5d5ecd687ad341cdde8721d330d9dafcc2f5%2F5dd0225229899045d4e2f4d28f4cd8d5cd591853-294x314.png?alt=media)

## Exporting display author names

You can also set whether to use the display name as the author name in the XFDF whenever exporting the annotations, by passing the option `useDisplayAuthor: true` to [exportAnnotations](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#exportAnnotations).

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  annotationUser: '1',
  // other constructor options
}, viewerElement).then(instance => {
  const { documentViewer, annotationManager } = instance.Core;

  annotationManager.setAnnotationDisplayAuthorMap((userId) => {
    if (userId === '1') {
      return 'Will Ricker';
    } else if (userId === '2') {
      return 'Jean-Luc Picard'
    } else {
      return 'Guest';
    }
  });

  annotationManager.setAnnotationDisplayAuthorMap(mapNames);

  documentViewer.addEventListener('annotationsLoaded', async () => {
    const xfdfString = await annotationManager.exportAnnotations({
      useDisplayAuthor: true,
    });

    // Save/use XFDF
  });
});
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  annotationUser: '1',
  // other constructor options
}, viewerElement).then(instance => {
  const { docViewer, annotManager } = instance;

  annotManager.setAnnotationDisplayAuthorMap((annotation) => {
    const userId = annotation.Author;
    if (userId === '1') {
      return 'Will Ricker';
    } else if (userId === '2') {
      return 'Jean-Luc Picard'
    } else {
      return 'Guest';
    }
  });

  annotationManager.setAnnotationDisplayAuthorMap(mapNames);

  docViewer.addEventListener('annotationsLoaded', async () => {
    const xfdfString = await annotManager.exportAnnotations({
      useDisplayAuthor: true,
    });

    // Save/use XFDF
  });
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

This is what the resulting XFDF would output the display name for `title` instead of the ID:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<square page="0" title="Will Ricker" rect="107.070,480.110,307.900,597.150" color="#E44234" flags="print" name="8b423bdb-5f8c-992f-3dce-3b2dc9a04ffe" subject="Rectangle" />
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Next steps

Learn more about [exporting annotations](/web/open-save-document/save.md) to XFDF or perhaps [user permissions](/web/annotation/annotationmanager/permissions.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/annotation/annotationmanager/display-authors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
