Atlaslog
Atlaslog / Field Notes / Styling & rendering
Field note · Styling & rendering

Printed map comes out 25% small because 96 and 72 DPI are mixed

Quick answer

A map laid out at `794x1123` px, the A4 size at 96 DPI, prints at 75% of the page with the scale bar reading 0.75 km for 1 km. The PNG is interpreted at 72 DPI when placed into the PDF, so 794 px becomes 11.03 in instead of 8.27 in.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet 1.9.x / puppeteer 21 / ImageMagick 7 / PDF export
Symptom
Checklist
  1. Compare the exported bitmap's pixel size with A4 at 96 DPI, which is 794x1123
  2. Read the image's DPI metadata
  3. Measure the map's share of the PDF page and compare it with the 72/96 ratio
  4. Check `deviceScaleFactor` and viewport in the puppeteer script
  5. Decide the target print DPI before rendering
Fix

Render CSS at 96 DPI but capture at the print ratio: `deviceScaleFactor: 300 / 96` gives a 2481x3509 bitmap for A4 at 300 DPI, and declare the DPI on insert (`magick map.png -units PixelsPerInch -density 300`).

Code
# 查看图片 DPI 元数据
magick identify -verbose map.png | Select-String -Pattern "Resolution"

# 794 px 在 72 DPI 下 = 11.03 in,A4 宽 8.27 in -> 缩放到 75%
const A4_W = 8.27, A4_H = 11.69, DPI = 300;

await page.setViewport({
  width: Math.round(A4_W * 96),      // 794,CSS 布局仍按 96
  height: Math.round(A4_H * 96),
  deviceScaleFactor: DPI / 96        // 3.125,位图放大到 2481×3509
});

await page.screenshot({
  path: 'map-a4.png',
  clip: { x: 0, y: 0, width: 794, height: 1123 },
  type: 'png'
});
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Printed map comes out 25% small because 96 and 72 DPI are mixed. https://www.jingweizhi.com/en/cookbook/print-dpi-misalign.html (accessed 2026-11-03).