DEV Community

Pavol Z. Kutaj
Pavol Z. Kutaj

Posted on

1

How I'm Automating `resume.pdf` creation with Git Hooks and Pandoc

USECASE

The aim of this pageđź“ť is to explain how I automatically convert a Markdown file with my resume into a PDF using with a Git hook. My resume is available at https://pavol.kutaj.com. It is running on Github Pages (i.e. on Jekyll). I am trying to have a short NOW section on the top of the CV that I'm updating at least every querted. With this tiny automatin, each time I edit an index.markdown file, an accompanying .pdf is generated locally with pandoc and the pushed together with the commit of index.markdown. The pdf for download is available at https://pavol.kutaj.com/assets/Pavol-Kutaj-Resume.pdf.

  • Install Pandoc: Use Homebrew to install Pandoc:
  brew install pandoc
Enter fullscreen mode Exit fullscreen mode
  • Install MacTeX: Use Homebrew to install MacTeX for PDF generation:
  brew install --cask basictex
Enter fullscreen mode Exit fullscreen mode
  • Convert Markdown to PDF: Use Pandoc with custom geometry settings:
  pandoc -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm" -f markdown-implicit_figures -o "./assets/Pavol-Kutaj-Resume.pdf" index.markdown
Enter fullscreen mode Exit fullscreen mode
  • Create Git Hook: Navigate to the Git hooks directory:
  cd .git/hooks
Enter fullscreen mode Exit fullscreen mode
  • Create Pre-commit Hook: Create a pre-commit file and open it:
  touch pre-commit
  nano pre-commit
Enter fullscreen mode Exit fullscreen mode
  • Add Script to Pre-commit Hook: Add the following script:
  #!/bin/sh

  # Check if index.markdown is being committed
  if git diff --cached --name-only | grep -q 'index.markdown'; then
    # Run Pandoc command to convert Markdown to PDF
    pandoc -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm" -f markdown-implicit_figures -o "./assets/Placeholder-Resume.pdf" index.markdown

    # Add the generated PDF to the commit
    git add "./assets/Placeholder-Resume.pdf"
  fi
Enter fullscreen mode Exit fullscreen mode
  • Make Pre-commit Hook Executable: Set executable permissions for the hook:
  chmod +x pre-commit
Enter fullscreen mode Exit fullscreen mode
  • Testing the Setup: Ensure index.markdown and the ./assets/ directory exist. Run the commit process to verify the hook works.

LINKS

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay