I'm using Windows 10 and Ghostscript 10.02.1 (2023-11-01) installed via Scoop.
What doesn't work
If %d is followed by hex number or space or hyphen-minus, it doesn't work:
# PowerShell 7
gs -sDEVICE=jpeg -o "%d0.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%dF.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%d q.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%d-.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
(Or in CMD: gs -sDEVICE=jpeg -o "%dF.jpeg" -dFirstPage=1 -dLastPage=1 "test file.pdf")
The error message:
Page 1 GPL Ghostscript 10.02.1: **** Could not open the file '1-.jpeg'. **** Error: Page drawing error occurred. Could not draw this page at all, page will be missing in the output.
(Notice that the reported string is '1-.jpeg', which is exactly what I naively expect to get from "%d-.jpeg".)
What works
But if the very next symbol is not hexadecimal & not space & not hyphen-minus, it works:
# PowerShell 7
gs -sDEVICE=jpeg -o "%dG.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%dZ.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%d! 42 F0 0F.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
# or
gs -sDEVICE=jpeg -o "%d~.jpeg" -dFirstPage=1 -dLastPage=1 'test file.pdf'
(Or in CMD: gs -sDEVICE=jpeg -o "%dg.jpeg" -dFirstPage=1 -dLastPage=1 "test file.pdf")
A possible lead
The format specifier is of a form similar to the C printf format. [...] For more information, please refer to documentation on the C printf format specifications.
I didn't figure out anything of value by using a search engine for this.
“Conclusion”
The name I want is %d foo.jpeg. Of course, I can simply compromise with %dp foo.jpeg instead. But I'm curious about reasons of and workaround for this quirky syntax issue.