Skip to content

Commit a429fb8

Browse files
committed
Fix blurry PDF text on mobile Safari by accounting for devicePixelRatio
Canvas was rendered at CSS pixel dimensions, causing blurry upscaling on high-DPI screens (mobile Safari typically has devicePixelRatio of 2-3). Now renders at native device resolution and uses CSS to scale the canvas element back to logical size. https://claude.ai/code/session_01YcR4QgziQReqarBy3HuxcH
1 parent a82c351 commit a429fb8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

view-pdf.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,14 @@ <h2>${title}</h2>
313313

314314
const canvas = document.createElement('canvas');
315315
const context = canvas.getContext('2d');
316-
canvas.height = viewport.height;
317-
canvas.width = viewport.width;
316+
317+
// Render at device pixel resolution for sharp text on high-DPI screens
318+
const dpr = window.devicePixelRatio || 1;
319+
canvas.width = Math.floor(viewport.width * dpr);
320+
canvas.height = Math.floor(viewport.height * dpr);
321+
canvas.style.width = viewport.width + 'px';
322+
canvas.style.height = viewport.height + 'px';
323+
context.scale(dpr, dpr);
318324

319325
wrapper.appendChild(canvas);
320326

0 commit comments

Comments
 (0)