Bulk Convert Student Papers from .docx to .pdf with pandoc

When students submit papers electronically as .docx files, I prefer to convert them to .pdf files with a single format with a nice font. This makes them easier and more pleasant to read (and cuts down on trickery with fonts sizing, kerning, line spacing, and so on). Here’s an easy way to do this:

You’ll need to have rename, pandoc, and LaTeX (with xelatex) installed. Here’s the easy, three-step process:

  1. Download all the .docx files to a single directory
  2. Rename the files to remove spaces and replace them with underscores (which makes the next step easier): rename 's/ /_/g' *.docx.
    • Edit: You do not have to do this if you include quotation marks around "$i" in step 3. I just found it easier to deal with filenames without spaces.
  3. Create a simple for loop to run pandoc over all the files: for i in *.docx ; do echo "$i" && pandoc --variable mainfont="Minion Pro" --variable sansfont="Myriad Pro" --variable monofont="Inconsolata" --variable fontsize=12pt --latex-engine=xelatex "$i" -o "$i.pdf" ; done
    • You can change all the different fonts there that you want. I prefer Minion Pro, etc.

One you do this, you’ll have a set of nice, consistently formatted .pdf files that are easier and more pleasant to read.

Clark R. Donley
Philosophy PhD Candidate