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.
Symptom
- The map occupies about 75% of the A4 page, leaving blank space in the bottom right
- A 1 km scale bar measures 0.75 km on the printed sheet
- `magick identify -verbose map.png` reports a resolution of 72 DPI for the export
Checklist
- Compare the exported bitmap's pixel size with A4 at 96 DPI, which is 794x1123
- Read the image's DPI metadata
- Measure the map's share of the PDF page and compare it with the 72/96 ratio
- Check `deviceScaleFactor` and viewport in the puppeteer script
- 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
- Scaling the PNG up inside the PDF layout tool instead of fixing the DPI metadata, which leaves the scale bar wrong
- Changing `deviceScaleFactor` without resizing the viewport, so the CSS layout and the captured region no longer match
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
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).