Skip to content

Instantly share code, notes, and snippets.

@Qix-
Created September 17, 2021 12:02
Show Gist options
  • Save Qix-/75bbf665969acbf596c65df62f597359 to your computer and use it in GitHub Desktop.
Save Qix-/75bbf665969acbf596c65df62f597359 to your computer and use it in GitHub Desktop.
Drop this into a .bat somewhere and you can then drag+drop one ore more images onto it to create a multi-page PDF document.
@echo off
if %1.==. goto No1
bash -xc "a=(); for i in $(seq $#);do a+=(\"$(wslpath \"${!i}\")\"); done; convert \"${a[@]}\" -auto-orient \"output$(suffix() { local v=$(cat); if ! [ $v -eq 0 ]; then printf ' (%%s)' $v ; fi ; } ; find . -name 'output*.pdf' "|" grep -E '^\./output( \([0-9]+\))?\.pdf$' "|" wc -l "|" suffix ).pdf\"" -- %*
goto End
:No1
echo No documents dropped onto script; terminating.
pause
:End
@Qix-
Copy link
Author

Qix- commented Sep 17, 2021

Requires ImageMagick's convert utility.

If you're getting security errors from convert, run this once:

sudo sed -i_bak 's/rights="none" pattern="PDF"/rights="read | write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment