You can use one command line with two commands ( gs , convert ) connected via the channel, if the first command can write its output to stdout and the second can read its input from stdin.
- Fortunately, gs can write to stdout (
... -o %stdout ... ). - Fortunately, convert can read from stdin (
convert -background transparent - output.png ).
Problem resolved:
- GS is used to process the alpha channel with a special image,
- convert used to create a transparent background,
- to avoid writing a temporary file to disk.
Complete solution:
gs -sDEVICE=pngalpha \ -o %stdout \ -r144 cover.pdf \ | \ convert \ -background transparent \ - \ cover.png
Update
If you want to have a separate PNG per PDF page, you can use the %d syntax:
gs -sDEVICE=pngalpha -o file-%03d.png -r144 cover.pdf
This will create PNG files with the name page-000.png , page-001.png , ... (Note that %d -counting is zero - file-000.png corresponds to page 1 of the PDF, 001 - page 2. ..
Or, if you want to keep your transparent background for a 100-page PDF, do
for i in {1..100}; do \ \ gs -sDEVICE=pngalpha \ -dFirstPage="${i}" \ -dLastPage="${i}" \ -o %stdout \ -r144 input.pdf \ | \ convert \ -background transparent \ - \ page-${i}.png ; \ \ done
Kurt Pfeifle Jul 31 '10 at 20:14 2010-07-31 20:14
source share