34 lines
724 B
TypeScript
34 lines
724 B
TypeScript
import {
|
|
CSS_PIXELS_PER_INCH,
|
|
PDF_POINTS_PER_INCH
|
|
} from "@md-to-pdf/core";
|
|
|
|
export const PDF_PAGE_CSS_SCALE =
|
|
CSS_PIXELS_PER_INCH / PDF_POINTS_PER_INCH;
|
|
|
|
export function getPdfPageCssDimensions(
|
|
widthPoints: number,
|
|
heightPoints: number,
|
|
displayScale = 1
|
|
) {
|
|
return {
|
|
width: widthPoints * PDF_PAGE_CSS_SCALE * displayScale,
|
|
height: heightPoints * PDF_PAGE_CSS_SCALE * displayScale
|
|
};
|
|
}
|
|
|
|
export function getPdfCanvasRenderScale(
|
|
widthPoints: number,
|
|
displayWidthCssPixels: number,
|
|
devicePixelRatio: number
|
|
) {
|
|
if (
|
|
widthPoints <= 0 ||
|
|
displayWidthCssPixels <= 0 ||
|
|
devicePixelRatio <= 0
|
|
) {
|
|
return 0;
|
|
}
|
|
return (displayWidthCssPixels / widthPoints) * devicePixelRatio;
|
|
}
|