fix(pdf): keep upscaling to match viewport
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 34s

This commit is contained in:
enes 2024-09-17 14:41:54 +02:00
parent f35e2718ab
commit 43beac48e8

View File

@ -94,11 +94,14 @@ export const pdfToImages = async (
const pages: PdfPage[] = []
const pdf = await PDFJS.getDocument(data).promise
const canvas = document.createElement('canvas')
const width = getInnerContentWidth()
for (let i = 0; i < pdf.numPages; i++) {
const page = await pdf.getPage(i + 1)
const viewport = page.getViewport({ scale: 1 })
const originalViewport = page.getViewport({ scale: 1 })
const scale = width / originalViewport.width
const viewport = page.getViewport({ scale: scale })
const context = canvas.getContext('2d')
canvas.height = viewport.height
canvas.width = viewport.width
@ -106,7 +109,7 @@ export const pdfToImages = async (
await page.render({ canvasContext: context!, viewport: viewport }).promise
pages.push({
image: canvas.toDataURL(),
width: viewport.width,
width: originalViewport.width,
drawnFields: []
})
}