> 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/get-started/faq/supporting-xrefs.md).

# Supporting XRefs

World's #1 PDF SDK Library for Web, Mobile, Server, Desktop

## Supporting XRefs

XRefs (external references) are used within CAD documents to reference external documents to be loaded within a main document. WebViewer Server by default does not support these XRefs as it needs to know **context information about the location of the XRef files.**

We do provide an option `TRN_CAD_XREF_CONFIG_URL` that will allow you to provide this context information, but there are a few steps that will need to be done in order to use this option.

To use this option, you will need to do the following.

1. Determine a way to match XRefs to a document.
2. Create a server which will, given a request with a document, return the correct XRefs.
3. Add the XRef files to an accessible file location on WebViewer Server.
4. Set `TRN_CAD_XREF_CONFIG_URL` to the created server.

## Determine a way to match XRefs to a document

The most common way is by providing a header during the load document call, and then matching this header to the correct XRefs.

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

```js
WebViewer(...)
  .then(instance => {
    const options = {
      customHeaders: { MyDocIdentifier: "12345id" },
      filename: "Document.pdf"
    };
    const url = 'http://<documentserver>/mydocument.pdf'
    instance.loadDocument(url, options);
  });
});
```

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

Now the server will see `MyDocIdentifier` when WebViewer Server requests it, it can then return the **XRef paths** for this document like so:

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

```json
{
XRefSearchPaths: ['mypath/mpath/path', 'mypath2/path/path']
}
```

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

WebViewer Server would then look in these paths for XRefs.

## Create a server to return the XRefs

In the next step you will need to create a server that will do the following:

1. Accept a GET request
2. Read the a header from the request
3. Return XRefs based on this header in JSON format

**Paths returned by the server should have the following traits**

* They should be **absolute paths**
* They should point to the folder containing the external files
* The path should only be a local system path

The code below is a rough example of how you would do this. The specifics of how you implement XRef path selection will be specific to your system.

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

```python
from http.server import BaseHTTPRequestHandler,HTTPServer
import json

xrefPaths = { 
'docId1' : ['/path/path1/path', '/path/path2'], 
'docId2' : ['/path3/path']
}

class Server(BaseHTTPRequestHandler):
    def _set_headers(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()

    def do_HEAD(self):
        self._set_headers()

    def do_GET(self):
        self.send_response(200)
        self._set_headers()
        # here you would get each individual XRef path based on the ID
        # and return them in JSON below
        myId = self.headers["MyDocIdentifier"]
        myPaths = xrefPaths[myId]
        self.wfile.write(json.dumps({'XRefSearchPaths': myPaths }).encode())

def run(server_class=HTTPServer, handler_class=Server, port=8008):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)

    print('Starting httpd on port %d...' % port)
    httpd.serve_forever()

if __name__ == "__main__":
    run()
```

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

## Add the XRefs to the server

### Using Docker

In docker you should mount volumes at the specific XRef paths like so:

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

```yaml
volumes:
  /myfiledirectory/dir:/home/tomcat/xrefFiles
```

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

You would then set XRefs to be looked for inside of this xrefFiles directory.

### Using Windows

On windows, you only need to provide the correct paths and your XRefs should be found.

## Set TRN\_CAD\_XREF\_CONFIG\_URL

A prerequiste to this step would be to setup your server over a local network or the internet to be accessible by WebViewer Server. In this example, the server is hosted on `192.168.1.1` under the path `getXrefs`:

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

```yaml
TRN_CAD_XREF_CONFIG_URL: 'http://192.168.1.1/getXrefs'
```

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

If everything was done correctly, XRefs should now be appearing in your documents.


---

# 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/get-started/faq/supporting-xrefs.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.
