Skip to main content

Getting user documents

There are two ways to get a list of documents the user belongs to.

The main, recommended way to fetch documents is with the getDocumentPaginator function.

You can also get all a user's documents with the getAllDocuments function.

getDocumentPaginator#

This function is used to fetch the user's documents in a paginated manner. This is the recommended way to fetch documents.

getDocumentPaginator(options): Paginator

  • options (object) options to pass to the paginator
    • limit (number) how many entities to fetch with each request. This property is required.
    • orderBy ('updatedAt' | 'createdAt') how the entities should be ordered when querying. Defaults to 'updatedAt', meaning documents that were most recently updated will be fetched first
    • orderDirection ('ASC' | 'DESC') which direction the entities should be ordered when querying. Defaults to 'DESC' meaning newer documents are fetched first.
    • before (number - timestamp in MS) Sets the query to only fetch items that were updated/created at before this date. Used to fetch older documents. Defaults to the current time.

Returns a Paginator instance.

Example

import CollabClient from '@pdftron/collab-client'
const client = new CollabClient({...options})
// Create an array to store the documents we have fetched
const documents = [];
// Create a paginator that fetches 10 documents at a time
const paginator = client.getDocumentPaginator({
limit: 10
});
// Get the first ten documents and set them in our `documents` state
const firstTen = await paginator.next();
documents.push(...firstTen);
// Add an event listener to a 'Load More' button.
// This function fetches the next 10 documents
// and pushes them onto our state
document.getElementById('load-more-button').onclick = async () => {
const nextTen = await paginator.next();
documents.push(...nextTen);
}

getAllDocuments#

getAllDocuments(): Promise<Document[]>

Returns a list of all the user's documents.

This API should not be used in large scale applications, as it does not scale up with the number of documents a user belongs to.

Example

import CollabClient from '@pdftron/collab-client'
const client = new CollabClient({...options})
const documents = await client.getAllDocuments();