> 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/support/faq/what-is-a-document-event-1.md).

# What is a Document Event?

Learn about document events in SDKs - what counts as an event and how to optimize your operations. Understand file opening, creation, conversion, and saving processes. The Apryse support SDK streamlin

A document event occurs any time you open or create a new document using the SDK. In other words, any time you load a document into memory, it is counted as a document event.

Any operations that you make on a document after it's been loaded are not document events. You can perform as many operations on an opened document as you want without incurring additional document events.

{% hint style="info" %}
The following sections include just a few languages as examples, but the rules apply to all languages that our SDKs support.
{% endhint %}

## Opening files

In WebViewer, loading a new file into the viewer or into memory in any way counts as a document event. Interacting with that document after its loaded will not count as additional document events.

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

```js
JavaScriptWebViewer({
  // Counts as a document event
  initialDoc: 'https://myserver.com/myfile.pdf',
}, document.getElementById('viewer')).then(instance => {
  // Counts as a document event
  instance.UI.loadDocument('https://myserver.com/myfile.pdf', { filename: 'myfile.pdf' });
  instance.UI.addEventListener(UI.Events.TAB_MANAGER_READY, async () => {
    // Counts as a document event
    await UI.TabManager.addTab('https://myserver.com/myfile.pdf', { setActive: true });
  });
});
```

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

In the server-side SDKs, loading a new file into memory in any way counts as a document event.

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

```js
// Counts as a document event
const doc = await PDFNet.PDFDoc.createFromFilePath(filename);
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
// Counts as a document event
PDFDoc doc(filename);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
// Counts as a document event
PDFDoc doc = new PDFDoc(filename);
```

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

## Blank files

Creating a new blank file in WebViewer or the server SDKs counts as a document event.

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

```js
// Counts as a document event
const doc = await PDFNet.PDFDoc.create();
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
// Counts as a document event
PDFDoc doc;
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
// Counts as a document event
PDFDoc doc = new PDFDoc();
```

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

## Converting files

Some APIs allow you to convert a file and write it to disk. In the event where you want to perform additional operations on the converted file, loading it into memory will count as a document event.

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

```js
// Counts as one document event
await PDFNet.Convert.fileToWord('./input.pdf', 'output.docx');
// Counts as a second document event
const doc = await PDFNet.PDFDoc.createFromFilePath('output.docx');
// This does not count as a document event
await PDFNet.Optimizer.optimize(doc);
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
Convert::WordOutputOptions wordOutputOptions;
// Counts as a document event
Convert::ToWord(filename, output_filename, wordOutputOptions);
// Counts as a second document event
PDFDoc doc(output_filename);
// This does not count as a document event
Optimizer::Optimize(doc);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
// Counts as a document event
Convert.toWord(filename, output_filename, wordOutputOptions);
// Counts as a second document event
PDFDoc doc = new PDFDoc(output_filename);
// This does not count as a document event
Optimizer.optimize(doc);
```

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

## Operations with multiple files

Operations that input multiple files may count as more than one document event. For example, merging two documents into one will count as two document events.

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

```js
// This counts as two document events, we are loading two documents into memory.
const firstDoc = await instance.Core.createDocument('url/to/first.pdf');
const secondDoc = await instance.Core.createDocument('url/to/second.pdf');
// This does not count as a document event, we are merging the two already open documents.
await firstDoc.insertPages(secondDoc);
// This is NOT a document event, the document is already loaded in memory.
await instance.UI.loadDocument(firstDoc);
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
// This counts as two document events, we are loading two documents into memory.
PDFDoc new_doc("file1.pdf");
PDFDoc doc("file2.pdf");
// This does not count as a document event, we are merging the two already open documents.
new_doc.InsertPages(0, doc, 1, doc.GetPageCount(), PDFDoc::e_none);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
// This counts as two document events, we are loading two documents into memory.
PDFDoc new_doc = new PDFDoc("file1.pdf");
PDFDoc doc = new PDFDoc("file2.pdf");
// This does not count as a document event, we are merging the two already open documents.
new_doc.insertPages(0, doc, 1, doc.getPageCount(), PDFDoc.InsertBookmarkMode.NONE, null);
```

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

In operations like merging, it is recommended that you merge one document into another (2 document events), rather than creating a new blank file and then merging two documents into it (which would be 3 document events).

## Saving files

Saving files does not count as a document event. After the document has been loaded into memory, you can save that document as many times as you want without incurring additional document events.

For example, you could load a file into memory (1 document event), and then convert that file to 5 different formats while only incurring 1 document event.

## Additional information

If you are still unsure about what counts as a document event, or you're not sure how many document events your project will use, please reach out to our [support team](https://apryse.com/support) for more information.


---

# 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/support/faq/what-is-a-document-event-1.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.
