Skip to content

Commit

Permalink
Update pdfjs-dist to 4.5.136
Browse files Browse the repository at this point in the history
  • Loading branch information
TaTo30 committed Aug 17, 2024
1 parent fa3ccd4 commit 98f60e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/vue-pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"vue": "^3.2.33"
},
"dependencies": {
"pdfjs-dist": "4.2.67"
"pdfjs-dist": "^4.5.136"
},
"devDependencies": {
"@types/node": "^18.16.3",
Expand Down
24 changes: 5 additions & 19 deletions packages/vue-pdf/src/components/layers/TextLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as PDFJS from 'pdfjs-dist'
import { onMounted, ref, watch } from 'vue'
import type { PDFPageProxy, PageViewport } from 'pdfjs-dist'
import type { TextLayerRenderParameters } from 'pdfjs-dist/types/src/display/text_layer'
import type { HighlightEventPayload, HighlightOptions, TextLayerLoadedEventPayload } from '../types'
import { findMatches, highlightMatches, resetDivs } from '../utils/highlight'
Expand All @@ -21,8 +20,7 @@ const emit = defineEmits<{
const layer = ref<HTMLDivElement>()
const endContent = ref<HTMLDivElement>()
const textDivs: HTMLElement[] = []
let textDivs: HTMLElement[] = []
function getHighlightOptionsWithDefaults(): HighlightOptions {
return Object.assign({}, {
Expand Down Expand Up @@ -56,27 +54,15 @@ async function findAndHighlight(reset = false) {
function render() {
layer.value!.replaceChildren?.()
textDivs.splice(0, textDivs.length)
const page = props.page
const viewport = props.viewport
const textStream = page?.streamTextContent({ includeMarkedContent: true, disableNormalization: true })
const parameters: TextLayerRenderParameters = {
textContentSource: textStream!,
viewport: viewport!,
container: layer.value!,
textDivs,
textDivProperties: new WeakMap(),
}
const task = PDFJS.renderTextLayer(parameters)
task.promise.then(async () => {
const textLayer = new PDFJS.TextLayer({ container: layer.value!, textContentSource: textStream!, viewport: viewport! })
textLayer.render().then(async () => {
textDivs = textLayer.textDivs
const textContent = await page?.getTextContent()
emit('textLoaded', {
textDivs,
textContent,
})
emit('textLoaded', { textDivs, textContent })
const endOfContent = document.createElement('div')
endOfContent.className = 'endOfContent'
layer.value?.appendChild(endOfContent)
Expand Down

0 comments on commit 98f60e1

Please sign in to comment.