Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

hyperlinks that span lines make all of both lines clickable #2422

Open
mslgam opened this issue Jun 19, 2015 · 9 comments
Open

hyperlinks that span lines make all of both lines clickable #2422

mslgam opened this issue Jun 19, 2015 · 9 comments
Labels
Verified The issue is verified.

Comments

@mslgam
Copy link

mslgam commented Jun 19, 2015

When a hyperlink (<a href...>) spans a line, clicking anywhere in either of the lines will activate the link.

I'm not using any command-line options (just 'wkhtmltopdf in.html out.pdf').

I'm running it under Kubuntu 14.04, and here's some more detail:
wkhtmltopdf -V outputs:
wkhtmltopdf 0.12.1 (with patched qt)
uname -srvp outputs:
Linux 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64

Here's an HTML file that demonstrates this bug:

<!DOCTYPE html>
<html lang="en">
  <body>
    <p>This is a long paragraph that will wrap. This text should be on the first line.
      <a href="http://www.google.com/">Here's a link that crosses a line.</a>
      <a href="http://www.yahoo.com/">Here's a link on the second line.</a>
      Here's some unlinked text.
    </p>
  </body>
</html>

A workaround I've found is to replace all spaces in the link text with &nbsp;'s so the link doesn't wrap.

@ashkulz
Copy link
Member

ashkulz commented Jun 19, 2015

Thanks for the very good bug report, I can confirm this is the case even with the development version.

@ashkulz ashkulz added the Verified The issue is verified. label Jun 19, 2015
@ashkulz
Copy link
Member

ashkulz commented Jun 19, 2015

Looks like QWebPrinter::elementLocation() uses RenderObject.absoluteBoundingBoxRect() which computes a bounding box that is the union of all the rectangles enclosing the text. In this pathological case, it means the complete area of the two lines. To really fix it, the signature of QWebPrinter::elementLocation() will have to be changed -- which will have to be thought about in detail.

@mslgam
Copy link
Author

mslgam commented Jun 22, 2015

Maybe the link could be split into two pieces (two separate hyperlinks pointing to the same destination), one per line?

@ashkulz
Copy link
Member

ashkulz commented Jun 22, 2015

Yeah, that's what I meant by changing the signature -- it would have to report multiple non-overlapping areas separately instead of a single area i.e. two segments of each line instead of a single block. If I'm going to change that, might as well look at other issues in this area (even some that you reported 😄) before changing the approach.

@ktpsu
Copy link

ktpsu commented Jul 7, 2015

Having problems with this as well. I'm also seeing that two links on the same line makes the whole line clickable... but to only one of the links.

@cmr5289
Copy link

cmr5289 commented Jan 20, 2016

Hey, I would like to take a look at this or help fix the issue as I currently use this project. I have looked into the QWebPrinter::elementLocation() and was unable to really pinpoint where that is in the files and how to go about addressing this issue.

@claweyenuk
Copy link

This issue happens in Windows 10 as well.

@nielsbox
Copy link

Bump, any update on this? @ashkulz

@nategasser
Copy link

Not a fix, but an ok workaround -- I used PHP DOM to preprocess the HTML before sending to wkhtmlpdf. If you split the text of each link on space, then link each word separately, concat them, and replace the original link, it works. Put a space after each word (except the last) and (at least in my tests) you can't even tell by looking at the PDF.

But yeah, a fix would be good :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Verified The issue is verified.
Development

No branches or pull requests

7 participants