I'd like to make a script on Mac OS 10.3 that converts a pdf to a png. I've been looking around bu开发者_运维知识库t I'm not sure if its even possible. I keep reading about a "sips" command but it doesn't seem to be available on 10.3, or at least this one. I typed man sips in the terminal and nothing came out. I have written a couple bash scripts and kind of understand how they work but was hoping this specific issue at work would be a good way to practice. I could probably write something that changes the name, but I'm not sure that would work in and of itself as the new png file would probably not actually work. Is there a way from the terminal to basically open preview, open each file and then save as a png? that would probably be the best option. Thanks
I don't have a suitable system to test on, but I think sips
appeared in 10.3. (It's definitely in 10.4.)
Just because there is no man page doesn't mean that it isn't there (try sips -h
or ls /usr/bin/sips
).
If it's there, Sorpigal's answer (+1) is good for the basic scripting, but replace
convert "$pdf" "${pdf%%.*}.png"
with
sips -s format png --out "${pdf%%.*}.png" "$pdf"
ImageMagick can do this
convert "your file.pdf" "output file.png"
You will have to install it since it's not available by default.
If you want to convert a large number of files, add a for loop
cd /some/directry/with/pdfs
shopt -s nullglob
for pdf in *{pdf,PDF} ; do
convert "$pdf" "${pdf%%.*}.png"
done
Which will create equivalently named PNG files for each PDF with a .pdf or .PDF extension in that directory.
Use the following shell script.
- Make bash file e.g.,
test.bash
for i in *.pdf; do
name=$i;
name=${name%.*};
sips -s format png $i --out ${name}.png;
done
- Enter the command
bash test.bash
10.3 is somewhat old, so can't try solutions.
But here is a tutorial http://www.mactech.com/articles/mactech/Vol.21/21.03/BasicImageManipulation/index.html how to convert via applescript and built-in Apple ImageEvents (what comes with 10.3). Simply try change the jpeg/tiff to pdf/png.
精彩评论