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

Internal links are not working in pdf generated from wkhtmltopdf #2153

Open
sriharichava opened this issue Jan 19, 2015 · 20 comments
Open

Internal links are not working in pdf generated from wkhtmltopdf #2153

sriharichava opened this issue Jan 19, 2015 · 20 comments

Comments

@sriharichava
Copy link

Dear Team,

i generated a pdf from html page by using the wkhtmltopdf.
I am using below command:
wkhtmltopdf --enable-internal-links test.html test.pdf
I pointed some internal links in pdf those are not working in the pdf, same working in html page.
I am using like below:
Target of the Link:
Content
Link to the Target:
Link Text

Please help me to resolve the Issue.

Thanks,
Srihari Chava

@ashkulz
Copy link
Member

ashkulz commented Jan 19, 2015

Please post the version, platform and example HTML.

@sriharichava
Copy link
Author

Dear Ashish,

Version:
wkhtmltopdf 0.12.2 (with patched qt)
Platform:
Windows server 2008 R2 Enterprise
Unable to upload the html file:
Unfortunately, we don't support that file type. Try again with a PNG, GIF, or JPG.

Regards,
Srihari Chava

@ashkulz
Copy link
Member

ashkulz commented Jan 20, 2015

HTML? Also try using <span id="whatever">content</span>

@html2pdf-rocket
Copy link

Here is another example of a page that doesn't have the internal links generated, any ideas why? The HTML looks acceptable.

http://www.sec.gov/Archives/edgar/data/789019/000119312514289961/d722626d10k.htm#tx722626_2

@mcahornsirup
Copy link

Verified. Same issue here.

@borkdude
Copy link

Same issue here.

@borkdude
Copy link

@sriharichava @mcahornsirup I had this issue when using an empty link. When I inserted a nbsp, it worked.

@radumas
Copy link

radumas commented Sep 29, 2015

Same issue with wkhtmltopdf 0.12.2.1 (with patched qt) on Ubuntu 14.04.3 LTS

@illegalnumbers
Copy link

Same issue, Ubuntu 14.04 as well

@mcahornsirup
Copy link

Nice. I'll try to use a nbsp...

@ghost
Copy link

ghost commented Jul 26, 2016

I'm having the same issue with a software that uses wkhtmltopdf.
Please see the thread in the following link and let me know if you'd like me to provide you with any other information.

http://forums.apricitysoftware.com/t/pdf-export-with-working-links/233/8

I added the latest comment in the thread, which seems like a interesting find, but I'm not a programmer so I don't know for sure. Thanks.

@justintocci
Copy link

justintocci commented Nov 21, 2016

same issue on Fedora release 24 with wkhtmltopdf 0.12.3 (with patched qt)

I tried adding a space, linking a bunch of different ways.

I also tried --enable-internal-links and --disable-external-links, no joy.

CentOS Linux release 7.0.1406 (Core) wkhtmltopdf 0.12.2.1 (with patched qt) works just fine so this would seem to be a regression.


I installed wkhtmltopdf 0.12.2.1 (with patched qt) on Fedora release 24 and it works so this is definitely a regression in 0.12.3:
downloaded wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
rpm -Uhv wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
dnf install libpng15
=>now links work

@cripton
Copy link

cripton commented Aug 24, 2017

I write this code in php to replace all the empty links adding a space in large generated html.

$pattern = "/(<a name=.*?>)(<\/a>)/";           
$replacement = "$1&nbsp;$2";                   
$html = preg_replace($pattern, $replacement, $htm);

@denning
Copy link

denning commented Sep 5, 2017

I'm having the same problem, but only on my headless server and not when I run locally. No empty links.

Local (links work)

  • Ubuntu 17.04
  • wkhtmltopdf 0.12.3.2

Remote (links don't work)

  • Ubuntu 16.04.3
  • wkhtmltopdf 0.12.2.4

@Tomsgu
Copy link
Contributor

Tomsgu commented Aug 22, 2018

Does this work in 0.12.5?

@bluespidernav
Copy link

Tested in version 0.12.5 (windows 64 bit) and internal links ARE MOST DEFINITELY NOT WORKING. Simple ID based links using href with hash ID's appear to be translated into external links (none are empty). Headless Chrome (as well as being slower) can't do links at all and now it would seem wkhtmltopdf has the same issue even though according to the conversation here it may have previously been fixed (and broken again). Hoping it may once again be correctly supported some day as when it comes to generating PDF's with bookmarks wkhtmltopdf seems to be the only hope.

@bluespidernav
Copy link

And Re-tested this time with the same version 0.12.5 but this time with a linux build
CentOS 7 | x86_64 / i686 | Package (.rpm) built on CentOS 7.4.1804
AND links actually work. So it appears that the issue is resolved in the linux builds (or at least in this one) but not in the windows build. Will be trying an Ubuntu build sometime soon once my hosting provider has setup the new server!

@icnocop
Copy link
Contributor

icnocop commented Apr 10, 2019

The links in this HTML file work fine for me on Windows 10 64-bit Version 1809 (OS build 17763.292) using wkhtmltopdf 0.12.5-1.msvc2015-win64:

<!DOCTYPE html>
<html>
  <head>
<title>Page 1</title>
  </head>
  <body>
    <h1>Page 1</h1>
    <p>This is the page.</p>
<p>This page has links.</p>
<a href="#section-1">Click me to go to Section 1.</a><br/>
<a href="#section-2">Click me to go to Section 2.</a><br/>
<a href="#section-3">Click me to go to Section 3.</a><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<span id="section-1">This is Section 1</span><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<span id="section-2">This is Section 2</span><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<span id="section-3">This is Section 3</span><br/>
  </body>
</html>

I opened the generated PDF in Adobe Acrobat Reader DC 2019.010.20098 and the links also work without issues.

Is your HTML is valid?
ex. https://validator.w3.org/

The link @ewartgh provided does not contain valid HTML.

@FilBot3
Copy link

FilBot3 commented Feb 8, 2021

I think I'm still having the same issues.

wkhtmltopdf --version
wkhtmltopdf 0.12.6

Note, I am using Pandoc to do this so I can convert my Markdown to HTML then to PDF. The toc links work in HTML, but not the PDF. Using evince on Fedora, I get weird HTML errors, and when opening the PDF in Firefox, nothing happens.

@FilBot3
Copy link

FilBot3 commented Feb 11, 2021

Disregard me. Worked after not using Pandoc to execute wkhtmltopdf.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests