UNPKG

html-to-pdf-converter

Version:

HTML to PDF converter with support for HEADERS, FOOTERS and page numbers

102 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./utils/index"); const mmPerInch = 25.4; const BROWSER_POINTS_PER_MM = 96 / mmPerInch; const PDF_POINTS_PER_MM = 72 / mmPerInch; class PdfPoints { constructor(n) { this._n = n; } static of(n) { return new PdfPoints(n); } add(x) { return new PdfPoints(this._n + x._n); } subtract(x) { return new PdfPoints(this._n - x._n); } } exports.PdfPoints = PdfPoints; class Millimeters { constructor(n) { this._n = n; } static of(n) { return new Millimeters(n); } add(x) { return new Millimeters(this._n + x._n); } subtract(x) { return new Millimeters(this._n - x._n); } toPixels() { // tslint:disable-next-line no-use-before-declare return Pixels.of(this._n * BROWSER_POINTS_PER_MM); } toPdfPoints() { return PdfPoints.of(this._n * PDF_POINTS_PER_MM); } toString() { return `${this._n}mm`; } } Millimeters.max = (a, b) => Millimeters.of(Math.max(a._n, b._n)); exports.Millimeters = Millimeters; class Pixels { constructor(n) { this._n = n; } static of(n) { return new Pixels(n); } toMillimeters(type) { switch (type) { case 'none': return Millimeters.of(this._n / BROWSER_POINTS_PER_MM); case 'floor': return Millimeters.of(Math.floor(this._n / BROWSER_POINTS_PER_MM)); case 'ceil': return Millimeters.of(Math.ceil(this._n / BROWSER_POINTS_PER_MM)); default: return index_1.unreachable(type); } } toString() { return `${this._n}px`; } } exports.Pixels = Pixels; exports.PrintMargin = { ofMillimeters: ({ top, right, bottom, left }) => ({ top: Millimeters.of(top), right: Millimeters.of(right), bottom: Millimeters.of(bottom), left: Millimeters.of(left), }), ofZero: () => ({ top: Millimeters.of(0), right: Millimeters.of(0), bottom: Millimeters.of(0), left: Millimeters.of(0), }), }; exports.PageSize = { of: (width, height) => ({ width: Millimeters.of(width), height: Millimeters.of(height), }), ofZero: () => ({ width: Millimeters.of(0), height: Millimeters.of(0), }), }; exports.pageSizeInMM = { A4: { portrait: exports.PageSize.of(210, 297), landscape: exports.PageSize.of(297, 210), }, }; //# sourceMappingURL=types.js.map