Я читал, что встраиваю шрифты в JSPDF, чтобы решить его, но, возможно, это слишком сложно для меня, или, возможно, я не понял, что я не понимаю, что я не могу понять, что я не могу понять. Независимо от того, что я пробовал, я не мог понять, как правильно его отобразить. Любая помощь будет высоко оценена.
Код: Выделить всё
const {
jsPDF
} = window.jspdf;
let darkModeFlag = true;
async function getOutputDivClone() {
return document.getElementById("output").cloneNode(true)
}
async function exportPDF() {
const outputDiv = await getOutputDivClone();
const wrapBoth = document.createElement('div');
wrapBoth.style.backgroundColor = darkModeFlag ? '#1E1E1E' : '#FFFFFF';
outputDiv.style.backgroundColor = darkModeFlag ? '#1E1E1E' : '#FFFFFF';
wrapBoth.appendChild(outputDiv);
document.body.appendChild(wrapBoth);
const contentWidth = wrapBoth.offsetWidth;
const contentHeight = wrapBoth.offsetHeight;
let doc = new jsPDF({
orientation: contentWidth > contentHeight ? 'l' : 'p',
unit: 'px',
format: [contentWidth, contentHeight]
});
await new Promise(resolve => {
doc.html(wrapBoth, {
callback: resolve,
x: 0,
y: 0,
margin: [0, 0, 0, 0],
html2canvas: {
scale: 1,
logging: false,
allowTaint: false,
useCORS: true
}
});
});
wrapBoth.remove();
if (doc.internal.getNumberOfPages() > 1) {
for (let i = doc.internal.getNumberOfPages(); i > 1; i--) {
doc.deletePage(i);
}
}
doc.save(`test.pdf`);
}
document.addEventListener('DOMContentLoaded', async () => {
await exportPDF()
alert("done")
})< /code>
[>]
{}
log: ƒ log()
length: 0
name: "log"
[[Prototype]]: ƒ
anonymous()
error: ƒ error()
warn: ƒ warn()
info: ƒ info()
debug: ƒ debug()
clear: ƒ clear()
table: ƒ table()
count: ƒ count()
countReset: ƒ countReset()
assert: ƒ assert()
dir: ƒ dir()
dirxml: ƒ dirxml()
timeStamp: ƒ timeStamp()
trace: ƒ trace()
group: ƒ group()
groupCollapsed: ƒ groupCollapsed()
groupEnd: ƒ groupEnd()
profile: ƒ profile()
profileEnd: ƒ profileEnd()
time: ƒ time()
timeEnd: ƒ timeEnd()
timeLog: ƒ timeLog()
[[Prototype]]: Object
По какой -то нечетной причине здесь html2canvas дает ошибку cors
Подробнее здесь: https://stackoverflow.com/questions/795 ... -corrupted
Мобильная версия