mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Improve PDF file view at high pixel density (#15624)
GitOrigin-RevId: 49cc936853109aac6c2eefb9da1f0e794215ae13
This commit is contained in:
parent
c656e99b38
commit
54088acb1b
1 changed files with 6 additions and 1 deletions
|
@ -35,14 +35,19 @@ const FileViewPdf: FC<{
|
|||
|
||||
const pdf = await PDFJS.getDocument(preview.url).promise
|
||||
|
||||
const scale = window.devicePixelRatio || 1
|
||||
|
||||
for (let i = 1; i <= pdf.numPages; i++) {
|
||||
const page = await pdf.getPage(i)
|
||||
const viewport = page.getViewport({ scale: 1 })
|
||||
const viewport = page.getViewport({ scale })
|
||||
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.classList.add('pdf-page')
|
||||
canvas.width = viewport.width
|
||||
canvas.height = viewport.height
|
||||
canvas.style.width = `${viewport.width / scale}px`
|
||||
canvas.style.height = `${viewport.height / scale}px`
|
||||
|
||||
element.append(canvas)
|
||||
page.render({
|
||||
canvasContext: canvas.getContext('2d'),
|
||||
|
|
Loading…
Reference in a new issue