diff --git a/src/plugin/hyperlinks.js b/src/plugin/hyperlinks.js index 8646d235..6df5e43f 100644 --- a/src/plugin/hyperlinks.js +++ b/src/plugin/hyperlinks.js @@ -11,31 +11,43 @@ var orig = { }; Worker.prototype.toContainer = function toContainer() { + var self = this; return orig.toContainer.call(this).then(function toContainer_hyperlink() { // Retrieve hyperlink info if the option is enabled. - if (this.opt.enableLinks) { - // Find all anchor tags and get the container's bounds for reference. - var container = this.prop.container; + + function storeLinkInfo(container, externalPage) { var links = container.querySelectorAll('a'); - var containerRect = unitConvert(container.getBoundingClientRect(), this.prop.pageSize.k); - linkInfo = []; + var containerRect = unitConvert(container.getBoundingClientRect(), self.prop.pageSize.k); // Loop through each anchor tag. Array.prototype.forEach.call(links, function(link) { - // Treat each client rect as a separate link (for text-wrapping). + // Treat each client rect as a separ nmate link (for text-wrapping). var clientRects = link.getClientRects(); for (var i=0; i adjustedPageHeight ? 'l' : 'p'] : []) + ); + var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality); - this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0], - this.prop.pageSize.inner.width, pageHeight); + this.prop.pdf.addImage(imgData, opt.image.type, mLeft, mTop, pageWidth, pageHeight); + } + + if (!this.prop._firstPageDeleted) { + this.prop.pdf.deletePage(1); + this.prop._firstPageDeleted = true; } }); }; diff --git a/type.d.ts b/type.d.ts index 58a82759..ee35cfbb 100644 --- a/type.d.ts +++ b/type.d.ts @@ -6,7 +6,7 @@ declare module "html2pdf.js" { type?: "jpeg" | "png" | "webp"; quality?: number; }; - enableLinks?: boolean; + enableLinks?: boolean | { id: string, page: number }[]; html2canvas?: object; jsPDF?: { unit?: string;