Skip to content

html strings to pdf cause current page's resource reload again #927

@pht1991

Description

@pht1991
Image Image Image

DocumentCloner.prototype.toIFrame = function (ownerDocument, windowSize) {
var _this = this;
var iframe = createIFrameContainer(ownerDocument, windowSize);
if (!iframe.contentWindow) {
return Promise.reject("Unable to find iframe window");
}
var scrollX = ownerDocument.defaultView.pageXOffset;
var scrollY = ownerDocument.defaultView.pageYOffset;
var cloneWindow = iframe.contentWindow;
var documentClone = cloneWindow.document;
/* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
if window url is about:blank, we can assign the url to current by writing onto the document
*/
var iframeLoad = iframeLoader(iframe).then(function () { return __awaiter(_this, void 0, void 0, function () {
var onclone, referenceElement;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.scrolledElements.forEach(restoreNodeScroll);
if (cloneWindow) {
cloneWindow.scrollTo(windowSize.left, windowSize.top);
if (/(iPad|iPhone|iPod)/g.test(navigator.userAgent) &&
(cloneWindow.scrollY !== windowSize.top || cloneWindow.scrollX !== windowSize.left)) {
this.context.logger.warn('Unable to restore scroll position for cloned document');
this.context.windowBounds = this.context.windowBounds.add(cloneWindow.scrollX - windowSize.left, cloneWindow.scrollY - windowSize.top, 0, 0);
}
}
onclone = this.options.onclone;
referenceElement = this.clonedReferenceElement;
if (typeof referenceElement === 'undefined') {
return [2 /return/, Promise.reject("Error finding the " + this.referenceElement.nodeName + " in the cloned document")];
}
if (!(documentClone.fonts && documentClone.fonts.ready)) return [3 /break/, 2];
return [4 /yield/, documentClone.fonts.ready];
case 1:
_a.sent();
_a.label = 2;
case 2:
if (!/(AppleWebKit)/g.test(navigator.userAgent)) return [3 /break/, 4];
return [4 /yield/, imagesReady(documentClone)];
case 3:
_a.sent();
_a.label = 4;
case 4:
if (typeof onclone === 'function') {
return [2 /return/, Promise.resolve()
.then(function () { return onclone(documentClone, referenceElement); })
.then(function () { return iframe; })];
}
return [2 /return/, iframe];
}
});
}); });
documentClone.open();
documentClone.write(serializeDoctype(document.doctype) + "");
// Chrome scrolls the parent document for some reason after the write to the cloned window???
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
documentClone.close();
return iframeLoad;
};

after import html2pdf.bundle.min.js by script,function toIFrame cloned the document element cause this problem,why do this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions