feat: reimport pdf
This commit is contained in:
@@ -113,6 +113,10 @@ const props = defineProps({
|
||||
type: File,
|
||||
default: null
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
fileName: {
|
||||
type: String,
|
||||
default: 'document.pdf'
|
||||
@@ -131,14 +135,26 @@ const baseScale = ref(1)
|
||||
let pdfDoc = null
|
||||
let renderTask = null
|
||||
|
||||
async function loadPdf(file) {
|
||||
if (!file) return
|
||||
async function loadPdf(source) {
|
||||
if (!source) return
|
||||
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const arrayBuffer = await file.arrayBuffer()
|
||||
let arrayBuffer
|
||||
|
||||
// Support URL
|
||||
if (typeof source === 'string') {
|
||||
const response = await fetch(source)
|
||||
if (!response.ok) throw new Error('Erreur lors du chargement du PDF')
|
||||
arrayBuffer = await response.arrayBuffer()
|
||||
}
|
||||
// Support File
|
||||
else {
|
||||
arrayBuffer = await source.arrayBuffer()
|
||||
}
|
||||
|
||||
const loadingTask = pdfjsLib.getDocument({ data: arrayBuffer })
|
||||
pdfDoc = await loadingTask.promise
|
||||
|
||||
@@ -251,9 +267,10 @@ function onWheel(e) {
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.file, async (newFile) => {
|
||||
if (newFile) {
|
||||
await loadPdf(newFile)
|
||||
watch([() => props.file, () => props.url], async ([newFile, newUrl]) => {
|
||||
const source = newUrl || newFile
|
||||
if (source) {
|
||||
await loadPdf(source)
|
||||
} else {
|
||||
pdfDoc = null
|
||||
totalPages.value = 0
|
||||
|
||||
Reference in New Issue
Block a user