Converting between formats with Pandoc
Pandoc is an all-purpose “Swiss-army knife” for converting from one markup format to another. Apart from Markdown, it also supports loads of other input and output formats, so it is often the easiest way to go from plain text to rich output like word processing documents, presentations, slides, and PDFs.
It is a command-line tool, but you can also try it online here.
Before trying these examples, complete the optional Pandoc setup and download and extract the workshop repository. Open a terminal in the extracted intro-markdown-HEAD directory, then change to its data directory:
$ cd data
Run the remaining commands from this directory.
Convert Markdown to Word or PDF
The workshop’s sample Markdown document includes headings, lists, images, and a table. Convert it to Microsoft Word with:
$ pandoc sample.md -o sample.docx
To create a PDF, use:
$ pandoc sample.md -o sample.pdf
Pandoc chooses the output format from the filename extension. See Creating a PDF for other PDF engines and options.
Convert Word to Markdown
Pandoc can read a .docx file and write Markdown:
$ pandoc sample.docx --extract-media=. -o sample-docx.md
The --extract-media=. option uses the current directory as the extraction root. Because a DOCX file stores embedded images in an internal media directory, Pandoc creates media/ beside sample-docx.md and updates the image references in the Markdown. Conversion is not always exact: review complex tables, equations, citations, comments, and layout after converting.
Recover text from a PDF
Pandoc cannot use PDF as an input format. A PDF stores the appearance of a page rather than its document structure, so converting one back to well-structured Markdown requires an intermediate text-extraction step and manual cleanup.
For a PDF that contains selectable text, install Poppler and use its pdftotext command to create a plain-text Markdown file:
$ pdftotext -layout document.pdf document.md
Plain text is valid Markdown, but the extracted file will not contain reliable Markdown structure. Add headings, lists, image references, and other markup manually. For a scanned PDF, perform optical character recognition (OCR) first. In either case, check the result against the original: headings, lists, columns, tables, footnotes, and image placement may be lost or misidentified.
Create presentations from Markdown
The sample presentation source uses level-two headings to begin new slides. Create a Beamer PDF presentation with:
$ pandoc sample-presentation.md -t beamer -o sample-presentation.pdf
Pandoc can also create an editable PowerPoint presentation directly:
$ pandoc sample-presentation.md -o sample-presentation.pptx
Conversion from .pptx to .md is also possible:
$ pandoc sample-presentation.pptx --extract-media=. -o sample-presentation-pptx.md
Pandoc does not write the native Google Slides format directly. Instead, generate the .pptx, upload it to Google Drive, and open it with Google Slides. Google can then convert the uploaded presentation to its native format. Check fonts, image placement, animations, and other layout details after importing.
For additional slide layouts, speaker notes, incremental lists, and themes, see Pandoc’s slide show documentation.
Loading last updated date...