Combine & Export Multiple (Obsidian) Markdown Files as PDF
Let me show you how you can easily export multiple markdown files to a PDF or any other format.
Have you also tried to export multiple Obsidian notes as one PDF and got frustrated that there is no good solution? Well, this post to the rescue.
My daily notes folder in Obsidian got rather long in 2022, so I took the time between Christmas and New Year’s to clean up some of my files and folders. I wanted to export all of my daily notes from last year as one PDF and then move the notes to an archive folder. Clean files, clean mind. This post uses the Obsidian daily notes as an example, but you can, of course, apply this method to any .md file. As with all things in life, there is more than one solution. Let me show you two.
Method 1
Create a new Obsidian .md file that contains internal links (in this format `![[filename]]`) to all notes you want to combine and then export this new summary file as PDF.
For example, my daily notes file names are equivalent to their creation date in simple ISO 8601 format. E.g. the file name of my daily note of January 1st 2022 is `2022–01–01.md`. So a summary markdown note in Obsidian with all daily notes of the last year would look like this:
# Annual Summary of Daily Notes
![[2022–01–01]]
![[2022–01–02]]
![[2022–01–03]]
…Now you can click on the app menu bar File > Export PDF to get your PDF. Done.
If you are lazy like me, you may not want to write all those links by hand. Here is a short python code that creates the markdown file for you.
````Python
import datetime
# set the start date and end date
start_date = datetime.date(2022, 1, 1)
end_date = datetime.date(2022, 12, 31)
#set the date format
#... e.g. "%Y-%m-%d", "%Y%m%d", "%B %d, %Y"
date_format = "%Y-%m-%d"
# create a list of dates from the start date to the end date
dates = [start_date + datetime.timedelta(n) for n in range(int((end_date - start_date).days))]
# print out the dates in the desired format
for date in dates:
print("![[{}]]".format(date.strftime(date_format)))
# OR
# open and write a .md file called "dates.md"
with open("dates.md", "w") as f:
# write the title to the file
f.write("# Annual Summary of Daily Notes\n")
# write the dates to the file
for date in dates:
f.write("![[{}]]\n".format(date.strftime(date_format)))
The above code produces a `.md` file with the name “dates.md” with links to all your daily notes of the year. Move this markdown file “dates.md” to your obsidian vault, open it in Obsidian and click File > Export PDF. Voilà, you exported all your daily notes from Obsidian as one PDF file.
Method 2
The second method is applicable to any text file you might have and uses Pandoc. Pandoc is a free TUI (terminal user interface) document converter, so for this option you will need some experience with Terminal or Shell commands.
For the second method, use the command-line tool Pandoc to combine multiple files from a single folder into a single output file. Here is an example of how you could do this in your terminal:
````Shell
pandoc -s file1.txt file2.txt file3.txt -o combined.txtThis command will use Pandoc to combine the three input files `file1.txt`, `file2.txt`, and `file3.txt` into a single output file `combined.txt`. The `-s` option specifies that the input files are stand alone documents, which means that they include a header and footer. The `-o` option specifies the name of the output file. Notice that you can use `.txt`or alternatively `.rtf`as output formatting.
More elegantly, you can move all the files you would like to export into one single folder, if you haven’t already. If you have a folder with all the files you would like to export you can use the `*` wildcard to specify all the files in the folder. This single line is all you need:
````Shell
pandoc -s foldername/*.md -o combined.rtfLet’s sum up
You can export multiple markdown files with several methods. If you use Obsidian and you would like to export several markdown files within Obsidian, use Method 1, which uses internal links of the files you want to export within a new summary document.
If you want a more generally applicable method that can convert pretty much any text file from one markup format into another, use Pandoc as described in Method 2.
I hope this post was helpful. Please let me know in the comment section what worked for you and which method you prefer, or if you have any advice you can share.
Before you leave:
- 👏 Clap for the story
- 📰 Subscribe for more posts like this Clemens Jarnach ⚡️
- 👉👈 Please follow me: Medium | Twitter | LinkedIn