"use strict"; define(function (require, exports, module) { class A4Utils { constructor() { let dpi = this.GetDPI(); let width_mm = 210; // A4纸宽度,单位:毫米 let height_mm = 297; // A4纸高度,单位:毫米 let width_px = this.MmToPixel(width_mm, dpi); let height_px = this.MmToPixel(height_mm, dpi); this.width = width_px; this.height = height_px; } /** * A4纸 */ GetDPI() { let tempDiv = document.createElement("div"); tempDiv.style.width = "1in"; tempDiv.style.visibility = "hidden"; document.body.appendChild(tempDiv); let dpi = tempDiv.offsetWidth; document.body.removeChild(tempDiv); return dpi; } MmToPixel(mm, dpi) { // 1 inch = 25.4 mm let inches = mm / 25.4; let pixels = inches * dpi; return Math.round(pixels); } } module.exports = new A4Utils(); })