Skip to content

Instantly share code, notes, and snippets.

@jak119
Last active October 3, 2015 19:50
Show Gist options
  • Save jak119/52ac98e26f6312246bcb to your computer and use it in GitHub Desktop.
Save jak119/52ac98e26f6312246bcb to your computer and use it in GitHub Desktop.
Pandoc to PDF
# This assumes that the script is being run from (or in the context of) a folder that contains all the original markdown files and that you've used a .md suffix
# Because my originals are kept in Sharepoint this only regenerates the files if the original markdown file has changed. This fixes versioning in Sharepoint
$originals = Get-ChildItem . -Filter *.md
foreach ($original in $originals){
$pdf_original = [System.IO.Path]::GetFileNameWithoutExtension($original) + ".pdf"
if ((!(Test-Path ..\$pdf_original)) -or (((Get-ItemProperty -Path $original -Name LastWriteTime).lastwritetime.DateTime) -ge ((Get-ItemProperty -Path ..\$pdf_original -Name LastWriteTime).lastwritetime.DateTime))) {
pandoc -V geometry:paperwidth=8.5in -V geometry:paperheight=11in -V geometry:margin=1in -s -S "$original" -o "..\$pdf_original"
}
}
foreach ($original in $originals){
$wiki_original = [System.IO.Path]::GetFileNameWithoutExtension($original) + "_wiki"+".txt"
if ((!(Test-Path ..\$wiki_original)) -or (((Get-ItemProperty -Path $original -Name LastWriteTime).lastwritetime.DateTime) -ge ((Get-ItemProperty -Path ..\$wiki_original -Name LastWriteTime).lastwritetime.DateTime))) {
pandoc -t mediawiki -s -S "$original" -o "..\$wiki_original"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment