DocsVuePluginsDocument Manager

Document Manager Plugin

The Document Manager Plugin is responsible for managing PDF documents in your viewer. It handles opening documents from URLs or local files, tracking document state (loading, loaded, error), and controlling which document is currently active.

This plugin is required for any PDF viewer, whether you’re displaying a single document or multiple documents. It provides the foundation for document lifecycle management and enables features like tab interfaces for multi-document applications.

Installation

The plugin is available as a separate NPM package.

npm install @embedpdf/plugin-document-manager

Registration

Import DocumentManagerPluginPackage and add it to the plugins array. You can configure initial documents to load automatically when the plugin initializes.

import { createPluginRegistration } from '@embedpdf/core' import { EmbedPDF } from '@embedpdf/core/vue' // ... other imports import { DocumentManagerPluginPackage } from '@embedpdf/plugin-document-manager/vue' const plugins = [ // Register the document manager plugin first createPluginRegistration(DocumentManagerPluginPackage, { // Optional: Load documents automatically on initialization initialDocuments: [ { url: 'https://example.com/document1.pdf' }, { url: 'https://example.com/document2.pdf' }, ], // Optional: Limit the maximum number of open documents maxDocuments: 10, }), // ... other plugins like Viewport, Scroll, Render, etc. createPluginRegistration(ViewportPluginPackage), createPluginRegistration(ScrollPluginPackage), createPluginRegistration(RenderPluginPackage), ]

Usage

1. Rendering the Active Document

Because the viewer can hold multiple documents in memory (e.g., in background tabs), you need a way to render only the currently active one.

The <DocumentContent /> component handles this logic for you. It takes a documentId and provides a scoped slot with the document’s status (isLoading, isError, isLoaded).

<script setup lang="ts"> import { DocumentContent } from '@embedpdf/plugin-document-manager/vue'; </script> <template> <div v-if="!activeDocumentId">No document selected</div> <DocumentContent v-else :document-id="activeDocumentId" v-slot="{ isLoading, isError, isLoaded }"> <LoadingSpinner v-if="isLoading" /> <ErrorMessage v-if="isError" /> <!-- Only render the heavy viewer components when loaded --> <Viewport v-if="isLoaded" :document-id="activeDocumentId"> <!-- ... Scroller, etc ... --> </Viewport> </DocumentContent> </template>

2. Opening Files

The plugin provides methods to open files from URLs or the user’s file system. Use the useDocumentManagerCapability composable to access these actions.

<script setup lang="ts"> import { useDocumentManagerCapability } from '@embedpdf/plugin-document-manager/vue'; const { provides: docManager } = useDocumentManagerCapability(); const handleOpenFile = async () => { // Opens the native system file picker // The plugin handles reading the buffer and creating the document await docManager.value?.openFileDialog(); }; const handleOpenUrl = () => { docManager.value?.openDocumentUrl({ url: 'https://example.com/report.pdf', password: 'optional-password' }); }; </script> <template> <button @click="handleOpenFile">Open File</button> </template>

3. Building a Tab Bar

To build a multi-document interface, you need to know which documents are open and which one is active. The useOpenDocuments and useActiveDocument composables provide this reactive state.

<script setup lang="ts"> import { useOpenDocuments, useActiveDocument, useDocumentManagerCapability } from '@embedpdf/plugin-document-manager/vue'; const documents = useOpenDocuments(); // Ref of all open document states const { activeDocumentId } = useActiveDocument(); const { provides: docManager } = useDocumentManagerCapability(); const handleTabClick = (docId: string) => { docManager.value?.setActiveDocument(docId); }; const handleClose = (e: Event, docId: string) => { e.stopPropagation(); docManager.value?.closeDocument(docId); }; </script> <template> <div class="tabs"> <div v-for="doc in documents" :key="doc.id" :class="{ active: doc.id === activeDocumentId }" @click="handleTabClick(doc.id)" > {{ doc.name }} <button @click="(e) => handleClose(e, doc.id)">x</button> </div> </div> </template>

Live Examples

Multi-Document Viewer with Tabs

This example demonstrates a complete PDF viewer with a tab bar for managing multiple documents. You can open multiple PDFs, switch between them using tabs, and close documents.

Password-Protected Document

This example shows how to handle password-protected documents. When you open a protected PDF, you’ll be prompted to enter the password. The example demonstrates detecting password errors, retrying with a password, and handling incorrect password attempts.

ℹ️

Try entering an incorrect password first to see the error handling, then enter the correct password (the password is “embedpdf”) to open the document.

API Reference

Configuration (DocumentManagerPluginConfig)

You can pass these options when registering the plugin with createPluginRegistration:

OptionTypeDescription
initialDocumentsInitialDocumentOptions[]An array of documents to load automatically when the plugin initializes. Each item can be either { url: string, documentId?: string, ... } or { buffer: ArrayBuffer, name: string, documentId?: string, ... }.
maxDocumentsnumberThe maximum number of documents that can be open simultaneously. If not specified, there is no limit.

Composable: useDocumentManagerCapability()

This composable provides access to all document management operations.

Returns

PropertyTypeDescription
providesRef<DocumentManagerCapability | null>A ref object with methods to manage documents, or null if the plugin is not ready.

DocumentManagerCapability Methods

MethodDescription
openDocumentUrl(options)Opens a document from a URL. Returns a Task<OpenDocumentResponse, PdfErrorReason>.
openDocumentBuffer(options)Opens a document from an ArrayBuffer. Returns a Task<OpenDocumentResponse, PdfErrorReason>.
openFileDialog(options?)Opens the browser’s native file picker. Returns a Task<OpenDocumentResponse, PdfErrorReason>.
closeDocument(documentId)Closes a specific document. Returns a Task<void, PdfErrorReason>.
closeAllDocuments()Closes all open documents. Returns a Task<void[], PdfErrorReason>.
setActiveDocument(documentId)Sets the active document. Throws an error if the document is not open.
getActiveDocumentId()Returns the ID of the currently active document, or null if none.
getActiveDocument()Returns the PdfDocumentObject of the active document, or null if none.
getDocumentOrder()Returns an array of document IDs in their current tab order.
moveDocument(documentId, toIndex)Moves a document to a specific position in the tab order.
swapDocuments(documentId1, documentId2)Swaps the positions of two documents in the tab order.
getDocument(documentId)Returns the PdfDocumentObject for a specific document, or null if not found.
getDocumentState(documentId)Returns the DocumentState for a specific document, or null if not found.
getOpenDocuments()Returns an array of all open DocumentState objects in tab order.
isDocumentOpen(documentId)Returns true if the document is currently open.
getDocumentCount()Returns the number of currently open documents.
getDocumentIndex(documentId)Returns the index of a document in the tab order, or -1 if not found.
retryDocument(documentId, options?)Retries loading a document that failed to load (e.g., with a new password). Returns a Task<OpenDocumentResponse, PdfErrorReason>.

Composable: useActiveDocument()

A convenience composable for accessing the active document.

Returns

PropertyTypeDescription
activeDocumentIdRef<string | null>The ID of the currently active document.
activeDocumentRef<DocumentState | null>The state of the currently active document.

Composable: useOpenDocuments(documentIds?)

A composable for accessing all open documents.

Returns

PropertyTypeDescription
documentStatesRef<DocumentState[]>A ref of all open documents in tab order. If documentIds is provided, returns only those documents in the specified order.

Component: <DocumentContent />

A headless component that provides loading, error, and loaded states for a specific document.

Props

PropTypeDescription
documentIdstring | null(Required) The ID of the document to render content for.

Scoped Slot Props

PropertyTypeDescription
documentStateDocumentStateThe full state object for the document.
isLoadingbooleantrue if the document is currently loading.
isErrorbooleantrue if the document failed to load.
isLoadedbooleantrue if the document has loaded successfully.

Events

The plugin emits events that you can subscribe to for reacting to document lifecycle changes:

EventTypeDescription
onDocumentOpenedEventHook<DocumentState>Emitted when a document is successfully loaded.
onDocumentClosedEventHook<string>Emitted when a document is closed. The payload is the document ID.
onActiveDocumentChangedEventHook<DocumentChangeEvent>Emitted when the active document changes.
onDocumentOrderChangedEventHook<DocumentOrderChangeEvent>Emitted when documents are reordered.
onDocumentErrorEventHook<DocumentErrorEvent>Emitted when a document fails to load.
Last updated on December 5, 2025

Need Help?

Join our community for support, discussions, and to contribute to EmbedPDF's development.