Created
February 28, 2025 01:53
-
-
Save fanurs/0544df29af8914c46920f369296a628f to your computer and use it in GitHub Desktop.
A script to convert Markdown to PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if input file is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 input.md" | |
exit 1 | |
fi | |
# Get the input file | |
INPUT_FILE="$1" | |
# Check if input file exists | |
if [ ! -f "$INPUT_FILE" ]; then | |
echo "Error: File '$INPUT_FILE' not found." | |
exit 1 | |
fi | |
# Extract basename without extension | |
BASENAME="${INPUT_FILE%.*}" | |
# Run pandoc with Docker to convert markdown to PDF | |
docker run --rm -v "$(pwd):/data" pandoc/latex "$INPUT_FILE" -o "$BASENAME.pdf" \ | |
-V geometry:letterpaper \ | |
-V geometry:left=0.75in \ | |
-V geometry:right=0.75in \ | |
-V geometry:top=0.75in \ | |
-V geometry:bottom=1in \ | |
-V fontsize=12pt \ | |
-V documentclass=report | |
# Check if conversion was successful | |
if [ $? -eq 0 ]; then | |
echo "Conversion successful: '$BASENAME.pdf' created." | |
else | |
echo "Error: Conversion failed." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment