@credentum/paper-size-convert
v0.0.1
Published
Get paper dimensions (mm, inches, pixels) for ISO 216, US, ANSI, and JIS paper sizes with DPI conversion.
Downloads
13
Maintainers
Readme
@credentum/paper-size-convert
Get paper dimensions in mm, inches, or pixels at any DPI. Covers ISO 216 (A/B/C series), US (Letter/Legal/Tabloid), ANSI (A–E), and JIS B series.
Installation
npm install @credentum/paper-size-convertUsage
import { getPaperSize } from '@credentum/paper-size-convert';
getPaperSize('A4'); // { width: 210, height: 297, unit: 'mm' }
getPaperSize('Letter', 'in'); // { width: 8.5, height: 11, unit: 'in' }
getPaperSize('A4', 'px', 300); // { width: 2480, height: 3508, unit: 'px' }Why Use This?
Every PDF generator, canvas renderer, and print stylesheet needs paper dimensions. The existing npm packages (paper-size, @5no/paper-sizes) are abandoned with single-digit weekly downloads. This package gives you all major paper standards with optional DPI-to-pixel conversion in one zero-dependency call.
API
getPaperSize(name, unit?, dpi?)
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| name | string | — | Paper size name (case-insensitive): A0–A10, B0–B10, C0–C10, Letter, Legal, Tabloid, Ledger, ANSI-A–ANSI-E, JIS-B0–JIS-B10 |
| unit | 'mm' \| 'in' \| 'px' | 'mm' | Output unit |
| dpi | number | 72 | Dots per inch (only used when unit is 'px') |
Returns: { width: number, height: number, unit: string }
Throws: Error if the paper name is not recognized, or if dpi is not a positive number.
listPaperSizes()
Returns an array of all supported paper size names.
Supported Sizes
- ISO 216 A series: A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10
- ISO 216 B series: B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10
- ISO 216 C series (envelopes): C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10
- US sizes: Letter, Legal, Tabloid, Ledger
- ANSI sizes: ANSI-A, ANSI-B, ANSI-C, ANSI-D, ANSI-E
- JIS B series: JIS-B0 through JIS-B10
License
MIT
