4

I am trying to convert from html to pdf with Pandoc. The output is pretty nice, still with the command pandoc index.html -o output.pdfI lose all my internal links (from table of contents to chapters, from text to footnotes, etc).

In my HTML this is the outdegree link

<p class="calibre18"><a href="#calibre_link-73"><span class="calibre8">CHAPTER ONE</span></a><br class="calibre19"></br><a href="#calibre_link-73">The Ever Expanding Domain of Computation</a></p>

which then lands here

<a href="#calibre_link-73">Chapter 1</a> makes the case that because of...

and here

<p class="calibre18"><a href="#calibre_link-73"><span class="calibre8">CHAPTER ONE</span></a><br class="calibre19"></br><a href="#calibre_link-73">The Ever Expanding Domain of Computation</a></p>...

Is there any way to keep all the links also in the output?

CptNemo
  • 6,455
  • 16
  • 58
  • 107
  • 1
    I tested it with a link to a `h3` element and pandoc perfectly converts to LaTeX, and therefore surely also to PDF. – koppor Oct 07 '15 at 04:50

2 Answers2

2

The Pandoc User's Guide section on Internal Links says

Internal links are currently supported for HTML formats (including HTML slide shows and EPUB), LaTeX, and ConTeXt.

This suggests that internal links aren't currently supported for PDF output, even though the PDF output is generated via LaTeX.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
  • Is there any alternative then you would suggest? I would like to have a nice formatted PDF from a mobi (or epub) file. I have no problem converting mobi to html (calibre does a good job with that). But then I still need the html-> pdf step. – CptNemo Aug 25 '13 at 11:28
  • @CptNemo It's probably worth asking the question on a Pandoc-specific forum, such as https://groups.google.com/forum/#!forum/pandoc-discuss. Maybe it is possible via some route, or maybe there's another tool that can add table of content entries in to a generated PDF afterwards. – Matthew Strawbridge Aug 25 '13 at 16:47
1

Internal links should work straightforwardly in PDF. However, for printing purposes, the default is not to color them. Have you tried clicking on the text that should be a link?

John MacFarlane
  • 8,511
  • 39
  • 33
  • Yes, I tried clicking. I also tried exporting again pandoc's PDF to HTML with Acrobat (it always keeps the links). The links were gone. (I edited my question) – CptNemo Aug 25 '13 at 22:44
  • Oh, I'd missed the fact that you were converting from HTML. The examples help, too. The released version of pandoc does not parse an HTML span tag into anything that has meaning in other formats. Internal links in markdown source will work, though. – John MacFarlane Aug 26 '13 at 03:18
  • So, should be possible to keep the links? – CptNemo Aug 26 '13 at 03:21
  • 1
    Not without restructuring the source. If you used an h1 tag with an id for the chapter heading, the link would work. – John MacFarlane Aug 26 '13 at 03:25