API
Types
TypeScript type reference for KViewer
All types are importable from kviewer:
import type { ExportPdfOptions, ViewerTabItem, AddTabOptions } from 'kviewer'
ExportPdfOptions
Options for KViewer.exportPdf().
interface ExportPdfOptions {
/** Burn annotations into PDF page content (non-editable). Default: false */
flatten?: boolean
/** Trigger browser file download. Default: false */
download?: boolean
/** Custom filename for download. Auto-generated if omitted. */
fileName?: string
/** Keep unmodified native PDF annotations. Default: false */
preserveOriginalAnnotations?: boolean
}
ViewerTabItem
Defines a tab in KViewerTabs.
interface ViewerTabItem {
/** Unique tab identifier */
id: string
/** Display label in the tab bar */
label: string
/** PDF source: URL string, Uint8Array, or pdfjs-dist init params */
source: string | Uint8Array | object
/** Lucide icon name. Default: 'i-lucide-file-text' */
icon?: string
/** Whether the tab can be closed. Default: true */
closable?: boolean
/** View mode override for this tab */
viewMode?: ViewMode
/** Zoom override for this tab */
zoom?: number
/** Shape detection override for this tab */
shapeDetection?: boolean
}
AddTabOptions
Options for KViewerTabs.addTab().
interface AddTabOptions {
/** Insert at specific index. Default: end */
index?: number
/** Switch to the new tab. Default: true */
activate?: boolean
}
StampDefinition
Defines a stamp for the stamp annotation tool.
interface StampDefinition {
/** Unique stamp identifier */
id: string
/** Display name in stamp picker */
name: string
/** Image source (URL, SVG path, or base64) */
imageUrl: string
/** Optional preview thumbnail URL */
previewUrl?: string
/** Default width in points */
width?: number
/** Default height in points */
height?: number
}
SignatureData
Represents a saved user signature.
interface SignatureData {
/** Unique signature identifier */
id: string
/** Base64 data URL or image URL */
imageUrl: string
/** Optional display name */
name?: string
}
SignatureHandlers
Callbacks for managing signature persistence.
interface SignatureHandlers {
/** Load all saved signatures */
onLoad: () => Promise<SignatureData[]>
/** Save a new signature. Returns the saved SignatureData */
onSave: (imageUrl: string) => Promise<SignatureData>
/** Delete a signature by ID */
onDelete: (id: string) => Promise<void>
}
IAnnotationStore
Serializable annotation state. Returned by getAnnotations() and accepted by importAnnotations().
interface IAnnotationStore {
/** Unique annotation ID */
id: string
/** 1-indexed page number */
pageNumber: number
/** Serialized Konva.js shape */
konvaString: string
/** Bounding box { x, y, width, height } */
konvaClientRect: IRect
/** Author name */
title: string
/** KViewer annotation type */
type: AnnotationType
/** Annotation color (hex) */
color?: string | null
/** PDF annotation subtype */
subtype: PdfjsAnnotationSubtype
/** Font size for text annotations */
fontSize?: number | null
/** pdfjs-dist annotation type number */
pdfjsType: PdfjsAnnotationType
/** pdfjs-dist editor type number */
pdfjsEditorType: PdfjsAnnotationEditorType
/** ISO date string */
date: string
/** Text or image content */
contentsObj?: IAnnotationContentsObj | null
/** Comment thread on this annotation */
comments: IAnnotationComment[]
/** Whether the annotation can be resized */
resizable: boolean
/** Whether the annotation can be dragged */
draggable: boolean
}
AnnotationType
Enum for KViewer annotation tool types.
enum AnnotationType {
NONE = -1,
SELECT = 0,
HIGHLIGHT = 1,
STRIKEOUT = 2,
UNDERLINE = 3,
FREETEXT = 4,
RECTANGLE = 5,
CIRCLE = 6,
FREEHAND = 7,
FREE_HIGHLIGHT = 8,
SIGNATURE = 9,
STAMP = 10,
NOTE = 11,
ARROW = 12,
CLOUD = 13,
}
FormFieldValue
Represents a form field's current value.
interface FormFieldValue {
/** Internal field identifier */
fieldId: string
/** PDF field name */
fieldName: string
/** Field type */
fieldType: FormFieldType
/** Current value */
value: string | boolean | string[]
}
FormFieldType
type FormFieldType = 'text' | 'checkbox' | 'radio' | 'dropdown' | 'signature' | 'button'
FormFieldDefinition
Full definition of a detected PDF form field.
interface FormFieldDefinition {
id: string
pageNumber: number
fieldType: FormFieldType
fieldName: string
rect: [number, number, number, number] // [x1, y1, x2, y2]
readOnly: boolean
required: boolean
shapeType?: 'rectangle' | 'circle' // For detected checkboxes
defaultValue?: string
maxLen?: number
multiLine?: boolean
password?: boolean
comb?: boolean
exportValue?: string
buttonValue?: string
options?: { displayValue: string; exportValue: string }[]
combo?: boolean
multiSelect?: boolean
editable?: boolean
buttonLabel?: string
fontSize?: number
color?: number[]
backgroundColor?: number[]
textAlignment?: number
}
ViewMode
type ViewMode = 'fit-width' | 'fit-page' | 'fit-height'
IAnnotationComment
interface IAnnotationComment {
id: string
title: string
date: string
content: string
status?: CommentStatus
}
enum CommentStatus {
Accepted = 'Accepted',
Rejected = 'Rejected',
Cancelled = 'Cancelled',
Completed = 'Completed',
None = 'None',
Closed = 'Closed',
}
IAnnotationContentsObj
interface IAnnotationContentsObj {
text: string
image?: string // Base64 encoded
}