Skip to content

Commit 6c04167

Browse files
authored
Merge pull request #1603 from privy-open-source/renovate/pdfjs-dist-5.x
docs(pdf-coordinate-finder): improve annotation area
2 parents fe336c6 + 39fd6cd commit 6c04167

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

src/components/pdf-viewer/PdfViewer.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ defineSlots<{
361361
@apply ring-info ring;
362362
@apply dark:ring-dark-info;
363363
}
364-
365-
.annotationWidget {
366-
@apply absolute;
367-
}
368364
}
369365
}
370366

src/components/pdf-viewer/utils/use-viewer.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ export function useViewer (container: Ref<HTMLDivElement>, viewer: Ref<HTMLDivEl
133133
const annotations = await page.getAnnotations() as PDFJSAnnotation[]
134134

135135
for (const data of annotations) {
136-
if (data.noHTML && !source.annotationLayer.annotationStorage.has(data.id)) {
136+
if (data.annotationType === 20 /* Widget */ && data.fieldType === 'Sig' && !source.annotationLayer.annotationStorage.has(data.id)) {
137137
const {
138138
pageWidth,
139139
pageHeight,
140140
pageX,
141141
pageY,
142142
} = source.viewport.rawDims as PDFJSRawDimension
143143

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]
144+
const width = data.rect[2] - data.rect[0]
145+
const height = data.rect[3] - data.rect[1]
146146

147147
const rect = normalizeRect([
148148
data.rect[0],
@@ -151,14 +151,26 @@ export function useViewer (container: Ref<HTMLDivElement>, viewer: Ref<HTMLDivEl
151151
page.view[3] - data.rect[3] + page.view[1],
152152
])
153153

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}%`
154+
const div = document.createElement('section')
155+
156+
div.dataset.annotationId = data.id
157+
div.tabIndex = 1000
158+
div.className = 'signatureWidgetAnnotation'
159+
div.role = 'img'
160+
div.id = `pdfjs_internal_id_${data.id}`
161+
div.style.zIndex = '0'
162+
div.style.left = `${(100 * (rect[0] - pageX)) / pageWidth}%`
163+
div.style.top = `${(100 * (rect[1] - pageY)) / pageHeight}%`
164+
165+
if (data.rotation === 0) {
166+
div.style.width = `${(100 * width) / pageWidth}%`
167+
div.style.height = `${(100 * height) / pageHeight}%`
168+
} else {
169+
div.style.width = `${(100 * height) / pageWidth}%`
170+
div.style.height = `${(100 * width) / pageHeight}%`
171+
172+
div.dataset.mainRotation = `${(360 - data.rotation) % 360}`
173+
}
162174

163175
source.annotationLayer.div.append(div)
164176
source.annotationLayer.annotationStorage.setValue(data.id, { div })

src/tools/pdf-coordinate-finder.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ layout: false
1818
import { reactive, ref } from 'vue-demi'
1919
import { withBase } from 'vitepress'
2020

21-
const scale = ref(1)
22-
const file = ref()
23-
const debug = ref(false)
24-
const src = usePreview(file, withBase('/assets/pdf/Calibrator-v3.pdf'))
21+
const scale = ref(1)
22+
const file = ref()
23+
const debug = ref(false)
24+
const debugAnnotation = ref(false)
25+
const src = usePreview(file, withBase('/assets/pdf/Calibrator-v3.pdf'))
2526

2627
const items = reactive([])
2728
const item = ref()
@@ -68,7 +69,7 @@ layout: false
6869
</script>
6970

7071
<style lang="postcss">
71-
.pdf-viewer--debug .annotationWidget {
72+
.pdf-viewer--debug .annotationLayer > section {
7273
@apply pointer-events-auto border-2 border-dashed border-info-emphasis bg-info-emphasis/5;
7374
@apply dark:border-dark-info-emphasis dark:bg-info-emphasis/5;
7475
}
@@ -77,7 +78,7 @@ layout: false
7778
<div class="flex w-full h-full">
7879
<p-pdf-viewer
7980
layout="fit"
80-
:class="{ 'pdf-viewer--debug': debug }"
81+
:class="{ 'pdf-viewer--debug': debugAnnotation }"
8182
:src="src"
8283
v-model:scale="scale">
8384
<template #header>
@@ -89,10 +90,13 @@ layout: false
8990
</p-button>
9091
</template>
9192
</p-dropzone>
92-
<div class="flex items-center px-2 space-x-2 shrink-0">
93+
<div class="flex items-center px-2 space-x-4 shrink-0">
9394
<p-checkbox v-model="debug">
9495
Show Debug
9596
</p-checkbox>
97+
<p-checkbox v-model="debugAnnotation">
98+
Show Annotation Area
99+
</p-checkbox>
96100
</div>
97101
<div class="flex flex-wrap gap-2 shrink-0 md:flex-nowrap">
98102
<p-button @click="add(198, 106)">

0 commit comments

Comments
 (0)