읽기 전용 뷰어
주문이나 청구의 첨부 파일처럼 읽어야 하지만 바뀌면 안 되는 문서가 있습니다. 이 예제는 그런 문서를 읽기 전용 뷰어에서 하나씩 보여 주고, 목록으로 전환하며, 버튼으로 내려받게 합니다.
html
<select id="documents">
<option value="0">청구서</option>
<option value="1">납품서</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: '청구서' },
{ src: '/orders/42/delivery-note.jpg', alt: '납품서' },
]
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]!)
})참고
editable: false에서는 도구 모음에 ‘편집’ 버튼이 없고, 회전 버튼은 화면의 이미지만 돌립니다.download: true는 문서를 원래 파일 이름 그대로 저장하는 버튼을 더합니다.download이벤트로 대신 서버에서 제공할 수 있습니다.wheelZoom: false이면 휠이 페이지를 스크롤하므로, 긴 페이지 안의 뷰어에 알맞습니다.- 새
src는 다음 문서를 불러오고 뷰어에 맞춥니다.