37 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-11-05 22:43:34 +08:00
"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();
})