File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -317,16 +317,21 @@ async function renderPage() {
317317 const page = await pdfDocument . getPage ( pageToRender ) ;
318318 const viewport = page . getViewport ( { scale } ) ;
319319
320- // Get fresh context and clear canvas
320+ // Account for retina displays
321+ const dpr = window . devicePixelRatio || 1 ;
321322 const ctx = canvasEl . getContext ( "2d" ) ! ;
322- ctx . clearRect ( 0 , 0 , canvasEl . width , canvasEl . height ) ;
323323
324- // Set canvas dimensions
325- canvasEl . width = viewport . width ;
326- canvasEl . height = viewport . height ;
324+ // Set canvas size in pixels (scaled for retina)
325+ canvasEl . width = viewport . width * dpr ;
326+ canvasEl . height = viewport . height * dpr ;
327+
328+ // Set display size in CSS pixels
327329 canvasEl . style . width = `${ viewport . width } px` ;
328330 canvasEl . style . height = `${ viewport . height } px` ;
329331
332+ // Scale context for retina
333+ ctx . scale ( dpr , dpr ) ;
334+
330335 // Clear and setup text layer
331336 textLayerEl . innerHTML = "" ;
332337 textLayerEl . style . width = `${ viewport . width } px` ;
You can’t perform that action at this time.
0 commit comments