From 28a757e5bb3152241e3b0632e239787e489838a3 Mon Sep 17 00:00:00 2001 From: Vytor Rennan <61885695+vytorrennan@users.noreply.github.com> Date: Fri, 26 Apr 2024 00:52:21 -0300 Subject: [PATCH] Fix bad resolution for pdfs (#23) --- pdf.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index bcadc11..19d937e 100644 --- a/pdf.js +++ b/pdf.js @@ -494,7 +494,13 @@ const annotationLayerBuilderCSS = ` ` const renderPage = async (page, getImageBlob) => { - const scale = devicePixelRatio + + const naturalPdfSize = page.getViewport({ scale: 1 }) + const naturalPdfRatio = naturalPdfSize.width / naturalPdfSize.height + const appRatio = innerWidth / innerHeight + const pdfToAppResolutionRatio = appRatio / naturalPdfRatio + + const scale = devicePixelRatio * pdfToAppResolutionRatio const viewport = page.getViewport({ scale }) const canvas = document.createElement('canvas')