Skip to content

Commit 796d351

Browse files
committed
Support hyperlink line-wrapping
1 parent 3c68257 commit 796d351

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/html2pdf.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ var html2pdf = (function(html2canvas, jsPDF) {
5555

5656
// Get the locations of all hyperlinks.
5757
if (opt.enableLinks) {
58+
// Find all anchor tags and get the container's bounds for reference.
59+
opt.links = [];
5860
var links = container.querySelectorAll('a');
5961
var containerRect = unitConvert(container.getBoundingClientRect(), pageSize.k);
60-
opt.links = Array.prototype.map.call(links, function(link) {
61-
var clientRect = unitConvert(link.getBoundingClientRect(), pageSize.k);
62-
clientRect.left -= containerRect.left;
63-
clientRect.top -= containerRect.top;
64-
return { el: link, clientRect: clientRect };
62+
63+
// Treat each client rect as a separate link (for text-wrapping).
64+
links.forEach(function(link) {
65+
var clientRects = link.getClientRects();
66+
for (var i=0; i<clientRects.length; i++) {
67+
var clientRect = unitConvert(clientRects[i], pageSize.k);
68+
clientRect.left -= containerRect.left;
69+
clientRect.top -= containerRect.top;
70+
opt.links.push({ el: link, clientRect: clientRect });
71+
}
6572
});
6673
}
6774

0 commit comments

Comments
 (0)