Skip to content

Instantly share code, notes, and snippets.

@pbfy0
Created July 17, 2018 20:10
Show Gist options
  • Save pbfy0/5e505a75c73e2f48a469dc39f5959168 to your computer and use it in GitHub Desktop.
Save pbfy0/5e505a75c73e2f48a469dc39f5959168 to your computer and use it in GitHub Desktop.
$ghostscript = "C:\Program Files\gs\gs9.22\bin\gswin64c.exe"
$sumatrapdf = "C:\Program Files\SumatraPDF\SumatraPDF.exe"
$filename = $args[0]
if($filename.EndsWith("_gs.pdf")) {
Start-Process $sumatrapdf -ArgumentList $filename
exit
}
$nfn = $filename -replace "\.pdf$","_gs.pdf"
if(Test-Path $nfn -PathType leaf) {
$orig_mt = (Get-Item $filename).LastWriteTime
$new_mt = (Get-Item $nfn).LastWriteTime
if($new_mt -ge $orig_mt) {
Start-Process $sumatrapdf -ArgumentList $nfn
exit
}
}
& $ghostscript -q -sDEVICE=pdfwrite -o $nfn $filename
Start-Process $sumatrapdf -ArgumentList $nfn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment