How to Merge Markdown Files and Convert to PDF

Updated 5 min read

Quick answer

To merge Markdown files and convert them to PDF, run pandoc 01.md 02.md -o merged.pdf, or upload the .md files to Google Drive and merge them with Merge Docs Pro with Save merged Docs as PDF ticked. Google Docs can also open and export single Markdown files, and a free online merger joins .md files.

Since 2024, Google Docs reads and writes Markdown natively, which handles one file well. Joining many files in order is the part that still needs a method.

Since October 2026, Google Docs can also open and edit .md files directly in Markdown Mode without converting them. It still opens one file at a time.

Merging Markdown files with pandoc

Use this when you are comfortable with a terminal and want a repeatable build from Markdown sources.

  1. Install pandoc. For PDF output you also need a LaTeX engine such as TeX Live or MiKTeX.
  2. Name the files in reading order, for example 01-intro.md, 02-setup.md.
  3. In the folder, run:
Terminal window
pandoc 01-intro.md 02-setup.md 03-usage.md -o merged.pdf
  1. For a table of contents, add --toc -s. For Word or EPUB, change the extension to merged.docx or merged.epub.

Result: One PDF built from all the files. Pandoc joins multiple input files with blank lines between them before converting.

To get one combined Markdown file instead, run this on Mac, Linux or Git Bash:

Terminal window
for f in 0*.md; do cat "$f"; echo; done > combined.md

The echo adds a blank line so a heading at the top of one file doesn’t stick to the last line of the previous file.

Merging Markdown files with the free online tool

Use this when you only need one combined .md file and don’t want to install anything.

  1. Open the free online Markdown merger.
  2. Add up to five .md files.
  3. Drag them into order and click Merge and Download.

Result: A single combined .md file. To turn it into a PDF, open it in Google Docs or run it through pandoc.

Combining Markdown files in Google Docs

Use this when you have a few files and want to review and edit the result before making the PDF.

  1. In Google Docs, turn on Tools > Preferences > Enable Markdown.
  2. Open each .md file in a text editor and copy its contents.
  3. In one Google Doc, right-click and choose Paste from Markdown. Repeat for each file, adding a page break with Ctrl + Enter (Windows) or Cmd + Enter (Mac) between them.
  4. Click File > Download > PDF document (.pdf).

Result: An editable Google Doc and a PDF. You can also export the combined Doc back to Markdown with File > Download > Markdown (.md).

Tip: To open a single Markdown file directly, use File > Open > Upload in Docs, or upload it to Drive and choose Open with > Google Docs.

Merging Markdown files with Merge Docs Pro

Use this when you have many files, mix Markdown with Google Docs or Word, or want PDF, Word and EPUB from one run.

  1. Upload the .md files to Google Drive.

  2. Open a Google Sheet and click Extensions > Merge Docs Pro > Merge Google Docs, then click Add Column Headers to Get Started.

  3. Click Select Google Docs or Drive Files to Merge and pick the Markdown files. Their File Type is set to Markdown automatically.

    Merge Docs Pro input sheet with several Markdown files listed and their File Type detected as Markdown

  4. Reorder the rows, and set Merge to No for any file you want to skip.

  5. Tick Add page break before each merge so each file starts on a new page.

    Merge Docs Pro options with Add page break before each merge ticked above the Merge Docs button

  6. Tick Save merged Docs as PDF, and optionally Save merged Docs as Word or Save merged Docs as ePUB.

    Merge Docs Pro options with Save merged Docs as PDF and ePUB ticked before merging Markdown files

  7. Click Merge Docs.

Result: One Google Doc plus the PDF and any other formats you selected. The full option list is in the Merge Docs Pro help.

Three Markdown files merged by Merge Docs Pro into one Google Doc and saved as a single PDF, each file in order

The same add-on can merge Markdown with Google Docs and Word files in one run.

Comparing the methods

MethodBest forWorks on
pandocRepeatable builds, Git repos, docs-as-codeWindows, Mac, Linux (command line)
Free online mergerA quick .md-only merge of up to five filesAny modern browser
Google Docs native MarkdownA few files you want to edit before exportGoogle Docs on a computer
Merge Docs ProMany files, mixed formats, PDF/Word/EPUB outputGoogle Sheets or Docs in a desktop browser

Platform differences

  • Windows: pandoc runs in PowerShell or Command Prompt. The for loop above needs Git Bash or WSL.
  • Google Docs: the Markdown preference, Paste from Markdown and Markdown download are for Docs on a computer.
  • Flavours differ. Tables, task lists, footnotes and front matter are extensions to CommonMark, so check how each tool handles them.

Troubleshooting

  • Images are missing. Relative paths like ./img/a.png only work where those files exist. Cloud tools need publicly accessible image URLs.
  • Headings merge into the previous paragraph. A file didn’t end with a blank line. Add one, or use pandoc, which inserts it for you.
  • pandoc says it can’t find pdflatex. Install a LaTeX distribution, or set another engine with --pdf-engine.
  • Front matter shows up as text. YAML blocks at the top of each file aren’t part of standard Markdown. Remove them before merging, or let pandoc read them as metadata.
  • Footnotes collide across files. In pandoc, add --file-scope so each file’s footnotes are kept separate.

For the PDF side of things, see how to combine Google Docs into a single PDF. If your sources are headed for LaTeX instead, read our Google Docs to LaTeX guide. More options are in the merge documents guides.

Frequently asked questions

How do I combine multiple Markdown files into one?

Concatenate them in order, for example with pandoc or a shell loop, or use an online Markdown merger. Use number prefixes in the file names so the order is predictable.

Can I merge Markdown files into one Google Doc?

Yes. Upload the .md files to Google Drive and merge them into one Google Doc with Merge Docs Pro, or import each with File > Open > Upload and copy them into one Doc.

How do I convert Markdown to PDF?

Use pandoc with a LaTeX engine installed, open the file in Google Docs and download it as a PDF, or merge the files with Merge Docs Pro and tick the PDF export.

Are images kept when I merge Markdown files?

Only if the tool can reach them. Cloud tools can't read images stored on your computer, so use publicly accessible image URLs.

Can I export merged Markdown to EPUB or Word?

Yes. Merge Docs Pro can save the merged document as PDF, Word or EPUB, and pandoc can write .epub and .docx files.