Reputation: 362
I am maintaining a set of documents in markdown which have links to other markdown documents and to webpages, and embedded images. I am looking for a tool which can convert these documents into a single pdf, while preserving all of those aspects of it (with links between documents pointing at the beginning of the corresponding document within the pdf).
The closest question, found here, does not have any answers which meet my requirements. Pandoc does not handle links within the document well, and follows relative links relative to my working directory, not where the markdown file in question is. The answer suggesting Typora only handles links within one document, which are not relevant to my use-case.
Are there any tools which enable me to do this?
Upvotes: 2
Views: 3070
Reputation: 1748
If I've understood you requirements correctly you want to merge pdfs that contain links to each other (as separate files) but that when they are combined the link no longer points to an external file but points to the correct part in this new document?
This can be achieved with pandoc, as per the answer you linked to:
pandoc *.md -o result.pdf
However, to get this to work as you wish you will have to change the links to the external files to reference the first header in that file. For example, I have two .md files (example1.md and example2.md)
example1.md
# This is document 1
Lorem ipsum ...
Link to [header 2, in this document](#header-2)
Link to [document 2](#this-is-document-2)
## Header 2
Lorem ipsum...
example2.md
# This is document 2
Lorem ipsum...
[This link should point to the 'first-document' part](#this-is-document-1)
When the above command is complete result.pdf
will work as you'd like.
As you can see the trick is to change what would have been a link to the other external .md files to internal links with the correct header.
How you do this is upto you but you could program this easily to make the desired changes across multiple documents.
Upvotes: 3