Skip to content

Repository files navigation

PDF Elements

A Vue 3 component for rendering PDFs with draggable and resizable element overlays.

Demo · Examples

image

Development

  • npm run dev - Run the demo with Vite
  • npm run build - Build the library (ESM + types)
  • npm run build:demo - Build the demo to dist-demo

API

Props

PropTypeDefaultDescription
widthString'100%'Container width
heightString'100%'Container height
initFilesArray[]PDF files to load
initFileNamesArray[]Names for the PDF files
initialScaleNumber1Initial zoom scale
showPageFooterBooleantrueShow page footer with document name and page number
hideSelectionUIBooleanfalseHide selection handles and actions UI
showSelectionHandlesBooleantrueShow resize/move handles on selected elements
showElementActionsBooleantrueShow action buttons on selected elements
readOnlyBooleanfalseDisable drag, resize, and actions for elements
ignoreClickOutsideSelectorsArray[]CSS selectors that keep the selection active when clicking outside the element
pageCountFormatString'{currentPage} of {totalPages}'Format string for page counter
autoFitZoomBooleanfalseAutomatically adjust zoom to fit viewport on window resize
pdfjsOptionsObject{}Options passed to PDF.js getDocument (advanced)

PDF.js options

pdfjsOptions is forwarded to PDF.js getDocument(...) and can be used to tune performance.

Example:

<PDFElements
:pdfjs-options="{
disableFontFace: true,disableRange: true,disableStream: true,}"
/>

Events

  • pdf-elements:end-init - Emitted when PDF is loaded
  • pdf-elements:adding-ended - Emitted when interactive placement ends. Payload: { reason: 'placed', object, docIndex, pageIndex } on success or { reason: 'cancelled' } when the placement is cancelled.

Exposed methods

  • startAddingElement(templateObject) - Starts interactive placement mode.
  • cancelAdding() - Cancels the current placement session and emits pdf-elements:adding-ended with { reason: 'cancelled' } when a session was active.

Slots

  • element-{type} - Custom element rendering (e.g., element-signature)
  • custom - Fallback for elements without specific type
  • actions - Custom action buttons

actions slot props

The actions slot receives:

  • object
  • onDelete
  • onDuplicate
  • toolbarClass (pdf-elements-actions-toolbar)
  • actionClass (pdf-elements-action-btn)
  • actionAttrs ({ 'data-pdf-elements-action': 'true' })

Use these hooks to style third-party button components consistently (for example, Nextcloud NcButton) without relying on internal scoped selectors.

Example:

<template #actions="slotProps">
<NcButton
:class="slotProps.actionClass"v-bind="slotProps.actionAttrs"
type="button"
variant="tertiary"
@click.stop="slotProps.onDuplicate"
>
Duplicate
</NcButton>
</template>

Theme variables

Action toolbar and action buttons can be themed via CSS variables and follow host theme tokens by default.

VariableDescription
--pdf-elements-toolbar-gapToolbar button gap
--pdf-elements-toolbar-paddingToolbar padding
--pdf-elements-toolbar-backgroundToolbar background color
--pdf-elements-toolbar-colorToolbar text/icon color
--pdf-elements-toolbar-border-colorToolbar border color
--pdf-elements-toolbar-border-radiusToolbar border radius
--pdf-elements-toolbar-shadowToolbar shadow
--pdf-elements-action-btn-borderAction button border
--pdf-elements-action-btn-backgroundAction button background
--pdf-elements-action-btn-colorAction button text/icon color
--pdf-elements-action-btn-paddingAction button padding
--pdf-elements-action-btn-radiusAction button border radius
--pdf-elements-action-btn-min-heightAction button min height
--pdf-elements-action-btn-min-widthAction button min width
--pdf-elements-action-btn-shadowAction button shadow
--pdf-elements-action-btn-hover-backgroundAction button hover background

About

No description, website, or topics provided.

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages