8

I'm trying to create a PDF document from an HTML document.

Of course it's easy to do this using the built-in PDF Printer, however, this does not retain hyperlinks.

I've tried wkhtmltopdf which looked very promising, but it crashes on every attempt.

Is anyone aware of any other options for generating a PDF document from an HTML document while retaining URL links?

Ian
  • 639
  • 2
  • 9
  • 16
  • I can't confirm if this works, but something you might consider is converting from HTML to LaTeX. Then convert from LaTeX to PDF since LaTeX is a common way to create hyperlinks in a PDF. – styfle May 31 '11 at 01:32

7 Answers7

7

The built-in Safari browser seems to do this when you do File -> Print -> PDF -> Save as PDF, it works for me as of Version 6 of Mac Safari.

Swaroop C H
  • 171
  • 1
  • 3
  • True, and this has worked in the same nice way in older versions too. [OmniWeb](http://www.omnigroup.com/products/omniweb/) did so too, but I have not used that for years, so things might have changed. – Arjan Aug 04 '12 at 10:54
  • Does it retain the hyperlinks for you? – Ian Aug 06 '12 at 21:34
  • Is there a way to automate this, like what wkpdf used to offer? – cnst Mar 24 '15 at 00:52
  • @Ian For me this retains "external" hyperlinks, but not links to within-page named anchors. – Cai Aug 09 '16 at 13:26
  • The built-in Safari browser preserves link *formatting* (e.g., blue underlined display text), but not clickable *links* (although Preview and Acrobat will automatically interpret URLs as clickable, even if they are not actually hyperlinked in the source document). – Lexible Sep 19 '18 at 17:29
  • Works on windows 11, chrome 100 – 27px Apr 14 '22 at 17:43
6

Found an answer over on SuperUser.com: wkpdf

Free, works perfectly. All hyperlinks retained.

Ian
  • 639
  • 2
  • 9
  • 16
  • Also good is wkhtmltopdf. Both of these tools are available via Homebrew on Mac OS. – Ian Mar 06 '13 at 18:42
  • no longer installs; author seems to have purposefully disabled installation in anticipation of future incompatibility; WTF? – cnst Mar 24 '15 at 00:52
  • There is an incompatibility with Yosemite from what I gather. – Ian Mar 24 '15 at 01:31
3

You can do this using Adobe Acrobat.

In Acrobat, go to File-> Create PDF-> From File. Select your HTML doc, let it do a bit of work, and then use File-> Save As to save it.

All hyperlinks will be intact.

Nathan Greenstein
  • 28,124
  • 24
  • 102
  • 135
1

Old question, but just found out if you open the .html in Microsoft Word and then save as pdf for online distribution, then the link works.

cyberguard
  • 11
  • 1
0

I have tried dompdf in the past and has worked very well for me. dompdf PHP

0

Check out the "Save as PDF" browser plugins:

Chrome plugin: https://chrome.google.com/extensions/detail/kpdjmbiefanbdgnkcikhllpmjnnllbbc

Firefox plugin: https://addons.mozilla.org/en-US/firefox/addon/save-as-pdf/

Both are free, but developed by a commercial company http://pdfcrowd.com. I tried the FF plugin, and except for some minor layout overlapping in the converted PDF document, all hyperlinks were clickable and working.

0

http://pdfcrowd.com only works, if the link is public - so no printing of pages, where you are logged in.

  • Yeap. I concur. If you print, say, a Gmail message or a SaaS wordpress site (in my case) where I'm logged in, it only prints the login page even though I'm NOT in the login page. – Lorgen GR Magpantay Jun 07 '20 at 21:21