Basic paper size detector.
npm install guess-paper-size
// import guess from 'guess-paper-size';
var guess = require('guess-paper-size');
var width = 210; // mm
var height = 297; // mm
var paper = guess(width, height);
if (paper) {
console.log('Detected ' + paper.size + ' paper, ' + paper.layout);
}
Test me in your browser using RunKit!
When found, JavaScript object returned:
- size - format name (e.g.
Letter
,A4
,B3
) - layout -
landscape
orportrait
When not found, return null
It's supposed to recognize all page sizes used by PDFKit:
- International formats:
4A0
;2A0
;A0
...A10
;B0
...B10
;C0
...C10
;RA0
...RA4
;SRA0
...SRA4
- US formats: Executive, Folio, Letter, Legal, Tabloid
- ISO 216 - Wikipedia
- Paper size - Wikipedia
- guess-paper-size at npmjs.com
- https://www.npmjs.com/package/paper-size - get paper dimensions by name