@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
99 lines (98 loc) • 4.41 kB
TypeScript
import { type Ref } from 'vue';
import { type AnnotationPluginApi, type Annotation } from '@vue-pdf-viewer/shared';
import type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist/types/src/display/api';
/**
* Set the global annotation plugin API reference
* Called from usePlugins when the plugin is registered
*/
export declare const setGlobalAnnotationPluginApi: (api: AnnotationPluginApi | null) => void;
/**
* Annotation Storage Composable with Automatic Save Support
*
* This composable provides a centralized way to manage PDF annotations with automatic
* saving capabilities. It tracks modifications and can automatically save annotations
* to the PDF document before operations like print and download.
*
* Key Features:
* - Tracks annotation modifications automatically
* - Provides methods to save annotations before print/download
* - Supports batch updates for better performance
* - Maintains reactivity across components
* - Returns updated PDF data for download operations
*
* Usage:
* ```typescript
* const {
* annotationStorage,
* hasModifications,
* saveAnnotationsToDocument,
* setAnnotationValue,
* batchUpdate
* } = useAnnotationStorage()
*
* // Set individual annotation
* setAnnotationValue('annotationId', { color: [255, 0, 0], noView: true })
*
* // Batch update multiple annotations
* batchUpdate([
* { key: 'id1', value: { color: [255, 0, 0] } },
* { key: 'id2', value: { noView: true } }
* ])
*
* // Save before print/download (returns updated PDF data)
* if (hasModifications()) {
* const updatedPdfData = await saveAnnotationsToDocument(pdfDocument)
* // Use updatedPdfData for download operations
* }
* ```
*/
export interface UseAnnotationStorageReturn {
annotationStorage: Ref<any>;
annotationEditorStorageMap: Ref<Map<string, any>>;
setStorage: (documentProxy: PDFDocumentProxy) => any;
batchUpdate: (updates: Array<{
key: string;
value: any;
}>) => void;
setAnnotationValue: (key: string, value: any, serialized?: boolean) => void;
hasModifications: () => boolean;
/** Save all annotations including underline/strikethrough (main entry point) */
saveAnnotationsToDocument: (documentProxy: PDFDocumentProxy) => Promise<Uint8Array | null>;
/** Save only regular PDF.js annotations (Highlight, FreeText, Stamp, Widget) */
saveAnnotationsToDocumentSimplified: (documentProxy: PDFDocumentProxy) => Promise<Uint8Array | null>;
cleanAnnotationStorage: () => void;
validateAnnotationData: (annotationData: any) => boolean;
renderTrigger: Ref<number>;
canvasRenderTrigger: Ref<number>;
cancelBatchUpdate: () => void;
/** Bulk-insert parsed annotations into the editor storage map. Returns generated keys. */
bulkImportAnnotations: (annotations: Annotation[]) => string[];
/** Remove all editor annotations from storage. Returns count of cleared entries. */
clearAllAnnotations: () => number;
/** The active annotation plugin API, or null when the plugin is not loaded. */
pluginApi: Ref<AnnotationPluginApi | null>;
ensureStorageInitialized: () => boolean;
getEditorKey: () => string;
getAnnotationById: (id: string) => any;
findEditorAnnotationKey: (annotationId: string) => string | undefined;
}
export declare const getGlobalStorageEntries: () => unknown[];
/**
* Pre-set noView flag for Underline/StrikeOut annotations before canvas rendering.
* This prevents race condition where canvas renders these annotations before
* LayerAnnotationEditor has a chance to hide them.
*
* Why this is needed:
* - Highlight annotations are supported by PDF.js for editing, so they respond to isEditing flag
* - Underline (type 10) and StrikeOut (type 12) are NOT supported by PDF.js for editing
* - PDF.js renders them on canvas but does NOT respond to isEditing flag
* - We need to set noView: true BEFORE canvas rendering starts
*/
export declare function prepareTextMarkupAnnotationsForCanvas(pageProxy: PDFPageProxy, isTextSelectionActive: boolean): Promise<void>;
/**
* Creates a serializable version of the annotation data
* @param value - The annotation data to serialize
* @returns A serializable version of the annotation data
*/
export declare function createSerializableAnnotation(value: any): Promise<any>;
export default function useAnnotationStorage(): UseAnnotationStorageReturn;