Skip to content

Read-only viewer ​

Some documents should be read but not changed, such as the attachments of an order or a claim. This example shows them one at a time in a read-only viewer, with a list to switch between them and a button to download them.

html
<select id="documents">
  <option value="0">Invoice</option>
  <option value="1">Delivery note</option>
</select>
<div id="viewer" style="height: 480px"></div>
ts
import { PaperPic } from '@paperpic/core'
import '@paperpic/core/style.css'

const documents = [
  { src: '/orders/42/invoice.jpg', alt: 'Invoice' },
  { src: '/orders/42/delivery-note.jpg', alt: 'Delivery note' },
]

const pic = new PaperPic(document.querySelector<HTMLElement>('#viewer')!, {
  ...documents[0],
  editable: false,
  download: true,
  wheelZoom: false,
})

document.querySelector('#documents')!.addEventListener('change', (event) => {
  const index = Number((event.target as HTMLSelectElement).value)
  pic.setOptions(documents[index]!)
})

Notes ​

  • With editable: false, the toolbar has no Edit button, and its rotate buttons only turn the image on display.
  • download: true adds a button that saves the document as it is, with its own file name. The download event lets you serve it from your server instead.
  • wheelZoom: false lets the wheel scroll the page, which suits a viewer inside a longer page.
  • A new src loads the next document and fits it to the viewer.

Released under the MIT License.