What is a Document Event?

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.

The following sections include just a few languages as examples, but the rules apply to all languages that our SDKs support.

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.

JavaScript

1JavaScriptWebViewer({
2 // Counts as a document event
3 initialDoc: 'https://myserver.com/myfile.pdf',
4}, document.getElementById('viewer')).then(instance => {
5 // Counts as a document event
6 instance.UI.loadDocument('https://myserver.com/myfile.pdf', { filename: 'myfile.pdf' });
7 instance.UI.addEventListener(UI.Events.TAB_MANAGER_READY, async () => {
8 // Counts as a document event
9 await UI.TabManager.addTab('https://myserver.com/myfile.pdf', { setActive: true });
10 });
11});

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

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

Blank files

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

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

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.

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

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.

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

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 for more information.


Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales