I am trying to automate my work of converting a PDF file to png using scons . The tool used for my conversion is convert from ImageMagick .
Here's the raw command line:
convert input.pdf temp/temp.pngconvert temp/*.png -append output.png
The first command will generate one PNG file for each page in the PDF file, so the goal of the first command is to dynamically list the files.
Here is the SConstruct file I'm working on:
convert = Builder(action=[ Delete("${TARGET.dir}"), Mkdir("${TARGET.dir}"), "convert $SOURCE $TARGET"]) combine = Builder(action="convert $SOURCE -append $TARGET") env = Environment(BUILDERS={"Convert": convert, "Combine": combine}) pdf = env.PDF("input.tex") pngs = env.Convert("temp/temp.png", pdf)
The code pngs = env.Convert("temp/temp.png", pdf) is actually wrong, since the goal is a few files that I don’t know how long before env.Convert is executed, so the final output.png contains only the first PDF file page.
Any hint is appreciated.
UPDATE:
I just found that I can use the convert input.pdf -append output.png to avoid a two-step conversion.
However, I am curious how to handle the scenario when the interim temporary list of files is unknown in advance and requires a dynamic target list.
source share