@@ -6,20 +6,23 @@ import {
66 shallowRef ,
77 watch ,
88} from 'vue-demi'
9- import type {
10- PDFJS ,
11- PDFJSViewer ,
12- } from './pdfjs'
13- import useLoading from '../../overlay/utils/use-loading'
14- import { useClamp , useMax } from '@vueuse/math'
15- import { createEventHook } from '@vueuse/core'
169import {
1710 createEventBus ,
1811 createLinkService ,
1912 createViewer ,
2013 getCMAPUri ,
2114 getDocument ,
15+ normalizeRect ,
16+ } from './pdfjs'
17+ import type {
18+ PDFJS ,
19+ PDFJSAnnotation ,
20+ PDFJSRawDimension ,
21+ PDFJSViewer ,
2222} from './pdfjs'
23+ import useLoading from '../../overlay/utils/use-loading'
24+ import { useClamp , useMax } from '@vueuse/math'
25+ import { createEventHook } from '@vueuse/core'
2326
2427export interface OpenDocConfig {
2528 disableStream ?: boolean ,
@@ -123,6 +126,47 @@ export function useViewer (container: Ref<HTMLDivElement>, viewer: Ref<HTMLDivEl
123126 scale . value = event . scale
124127 } )
125128
129+ bus . on ( 'annotationlayerrendered' , async ( event : { source : PDFJSViewer . PDFPageView , error ?: Error } ) => {
130+ if ( ! event . error ) {
131+ const source = event . source
132+ const page = source . pdfPage as PDFJS . PDFPageProxy
133+ const annotations = await page . getAnnotations ( ) as PDFJSAnnotation [ ]
134+
135+ for ( const data of annotations ) {
136+ if ( data . noHTML && ! source . annotationLayer . annotationStorage . has ( data . id ) ) {
137+ const {
138+ pageWidth,
139+ pageHeight,
140+ pageX,
141+ pageY,
142+ } = source . viewport . rawDims as PDFJSRawDimension
143+
144+ const width = ( data . rotation % 180 === 0 ) ? data . rect [ 2 ] - data . rect [ 0 ] : data . rect [ 3 ] - data . rect [ 1 ]
145+ const height = ( data . rotation % 180 === 0 ) ? data . rect [ 3 ] - data . rect [ 1 ] : data . rect [ 2 ] - data . rect [ 0 ]
146+
147+ const rect = normalizeRect ( [
148+ data . rect [ 0 ] ,
149+ page . view [ 3 ] - data . rect [ 1 ] + page . view [ 1 ] ,
150+ data . rect [ 2 ] ,
151+ page . view [ 3 ] - data . rect [ 3 ] + page . view [ 1 ] ,
152+ ] )
153+
154+ const div = document . createElement ( 'div' )
155+
156+ div . classList . add ( 'annotationWidget' , data . subtype , data . fieldType )
157+
158+ div . style . left = `${ ( 100 * ( rect [ 0 ] - pageX ) ) / pageWidth } %`
159+ div . style . top = `${ ( 100 * ( rect [ 1 ] - pageY ) ) / pageHeight } %`
160+ div . style . width = `${ ( 100 * width ) / pageWidth } %`
161+ div . style . height = `${ ( 100 * height ) / pageHeight } %`
162+
163+ source . annotationLayer . div . append ( div )
164+ source . annotationLayer . annotationStorage . setValue ( data . id , { div } )
165+ }
166+ }
167+ }
168+ } )
169+
126170 pdfEventBus . value = bus
127171 pdfLinkService . value = await createLinkService ( { eventBus : pdfEventBus . value } )
128172 pdfViewer . value = await createViewer ( {
0 commit comments