doc.html hangs indefinitely when passing size params on creation
Closed this issue · 2 comments
jspdf version: 2.5.1
enviorment: Chrome, windows 11
sample code:
async function exportPDF() {
const editorDiv = await getEditorDiv();
const outputDiv = await getOutputDivClone();
const wrapBoth = document.createElement('div');
wrapBoth.style.backgroundColor = darkModeFlag ? '#1E1E1E' : '#FFFFFF';
outputDiv.style.backgroundColor = darkModeFlag ? '#1E1E1E' : '#FFFFFF';
wrapBoth.appendChild(editorDiv);
wrapBoth.appendChild(outputDiv);
document.body.appendChild(wrapBoth);
let doc;
if (wrapBoth.offsetWidth > wrapBoth.offsetHeight) {
doc = new jsPDF('l', 'px', [wrapBoth.offsetWidth, wrapBoth.offsetHeight]);
} else {
doc = new jsPDF('p', 'px', [wrapBoth.offsetWidth, wrapBoth.offsetHeight]);
}
await new Promise(resolve => { doc.html(wrapBoth, { callback: resolve }) });
wrapBoth.remove();
doc.save(`${currentTab.name}.pdf`);
}it hangs indefinitely on await new Promise(resolve => { doc.html(wrapBoth, { callback: resolve }) });
when i create the new jsPDF with extra parmeters such as page orientation and size units and messures
when i simply create new jsPDF() it works fine (except the size ofc).
in console, the last debug output i get is from html2canvas
#1 0ms Starting document clone with size 1036x260 scrolled to 0,0
html2canvas.min.js:20 [Violation] Avoid using document.write(). https://developers.google.com/web/updates/2016/08/removing-document-write
fn.toIFrame @ html2canvas.min.js:20
(anonymous) @ html2canvas.min.js:20
(anonymous) @ html2canvas.min.js:20
(anonymous) @ html2canvas.min.js:20
(anonymous) @ html2canvas.min.js:20
a @ html2canvas.min.js:20
Js @ html2canvas.min.js:20
(anonymous) @ html2canvas.min.js:20
(anonymous) @ html.js:488
html2canvas.min.js:20 #1 662ms Document cloned, element located at -100000,0 with size 1019x260 using computed rendering
html2canvas.min.js:20 #1 662ms Starting DOM parsing
html2canvas.min.js:20 #1 689ms Starting renderer for element at -100000,0 with size 1019x260
html2canvas.min.js:20 #1 690ms Canvas renderer initialized (1019x260) with scale 1
and after that the whole page just becomes unresponsive and freezes, and i have to close the tab and reopen (relaod wont do it)
without size params, works fine!
any help would be greatly appricated!!
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
I get this issue on codes:
-Err in console: #1 0ms Starting document clone with size 2276x376 scrolled to 0,0
-File: html2canvas.js
-package: "jspdf": "^3.0.1",
-implementation:
import { jsPDF } from 'jspdf';
const doc = new jsPDF({
unit: "px",
orientation: "p",
format: [378, 378]
});
doc.html(html).then(value => {
doc.save(`${asset.assetNumber}.pdf`);
});