vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
52 lines (51 loc) • 1.29 kB
JavaScript
import { d as u } from "./dom-to-png-D2P_vWEM.js";
async function H({ domElement: d, fileName: f, scale: p = 2, options: P = {} }) {
if (!d) return Promise.reject("No domElement provided");
let r;
try {
r = (await import("jspdf")).default;
} catch {
return Promise.reject("jspdf is not installed. Run npm install jspdf");
}
const t = {
width: 595.28,
height: 841.89
}, o = await u({ container: d, scale: p });
return await new Promise((s, w) => {
const e = new window.Image();
e.onload = function() {
const i = e.naturalWidth, h = e.naturalHeight;
let g = t.width, l = t.width / i * h;
const n = new r("", "pt", "a4");
let c = 0, a = h;
const m = i / t.width * t.height;
if (a < m)
n.addImage(
o,
"PNG",
0,
0,
g,
l,
"",
"FAST"
);
else
for (; a > 0; )
n.addImage(
o,
"PNG",
0,
c,
g,
l,
"",
"FAST"
), a -= m, c -= t.height, a > 0 && n.addPage();
n.save(`${f}.pdf`), s();
}, e.onerror = (i) => w("Failed to load image for PDF: " + i), e.src = o;
});
}
export {
H as default
};