batch to convert pdf to jpg command prompt

hello I want to convert pdf to jpg in a batch and I'm using the:http://www.imagemagick.org/
 
   They way to use is simply:

 convert file.pdf file.jpg

Open in new window


   Now I want to do a batch in command prompt. I have a directory called c:\data inside that directory there are a lot of sub directories each directory by the same way inside has different pdf files with different names then I want that the batch look for all sub directories inside c:\data and then look inside each sub directory for the pdf files if found convert that pdf file inside the same directory where was found and exist the pdf found and with the same name than the original pdf and on that way with all sub directories and all pdf files. Of course some of that sub directories contain a lot of pdf files another sub directories have just one pdf or two and some has other kind of formats like flv, doc or whatever and that other formats different than pdf must not be touched must be converted the pdf files only. I tried to do this batch but doesn't work:

For /R C:\data %%I IN DO (.) convert "\%%I\*.pdf" "\%%I\*.jpg"

Open in new window

  Could anyone can help me in modify the script to make work and put the code?
Thank you so much
coerraceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duncanb7Commented:
Try this using forfile, window commnad, search all pdf at c: drive, and the read junk.txt file without its extension and convert it into jpg. All jpg files will be located the directory where this batch file you run, you can change it to other directory if need.

Duncan

@echo off
forfile /p "c:" /s /m *.pdf" >junk.text
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window

0
coerraceAuthor Commented:
I don't want to put the destination files in in one directory if you read the main topic I need the files  converted in each sub directory by different for example:
 a directory called "one" and another called "two"
   inside "one" there are these pdf files: 1.pdf, 2.pdf and 3.pdf and the directory "two" has these pdf files other1.pdf and other2.pdf
   These 2 directories are inside c:\data and the batch must convert for example when pass to directory "one" convert the files 1.pdf, 2.pdf and 3.pdf to 1.jpg, 2.jpg and 3.jpg and store in the same "one" directory and when the script pass to directory "two" must convert the other1.pdf and other2.pdf to other1.jpg and other2.jpg and store inside same "two" directory not in other. If in "one and "two" directories there  are .flv or any other extension different than pdf the script must ignore or not convert or touch the file.
   This is an example but c:\data could have hundred of directories not just "one" and "two" and all the files inside each sub directory must respect the location and must be together where the original pdf file reside but never throw in one directory all the conversion.
   Any modification to do this in the main script I posted?
   Thank you
0
duncanb7Commented:
you mean that search file and convert it to jpg file and put at the same location, right ?

Duncan
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

coerraceAuthor Commented:
well if the word search apply is search but for example when you use copy *.do  c:\ it grab just the .doc files to c:\ but maybe is not a kind of search but if apply the word is ok. In what I need is for each subdirectory convert only the pdf files and convert to jpg and store in same sub directory where pdf is and the rest of other extensions must be ignored and on that way for all sub directories inside c:\data
Thank you
0
duncanb7Commented:
So just, you mean that search pdf files at c: drive  and convert it to jpg files and save them at the same location they are converted from.

Duncan
0
coerraceAuthor Commented:
not c: is c:\data and inside c:\data there are a lot of subdirectories the pdf "search" must be in all subdirectories inside c:\data for example search in c:\data\one in c:\data\two and so on there are hundred of sub directories there, "one" and "two" are not real could be any name in that hundred of directories inside c:\data
Thank you
0
Joe Winograd, Fellow&MVEDeveloperCommented:
You want the mogrify command, not convert, because mogrify accepts a wildcard. This command should do it for you:

For /R C:\data %%I IN DO (.) mogrify -format jpg *.pdf

Open in new window


Regards, Joe
0
duncanb7Commented:
try this code, do it in example files and directory first, it will work,

@echo off
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window

0
Joe Winograd, Fellow&MVEDeveloperCommented:
I should have mentioned that <mogrify.exe> is in the same ImageMagick install folder as <convert.exe>, but you probably figured that out already. :)  However, the one-line code I posted is wrong. I'm very sorry about that — I feel really bad. Here's code that I just tested with mogrify and it works fine:

FOR /R "d:\0tempd\test\" %%I in (.) DO (
 Pushd %%I
 mogrify -format jpg *.pdf
 Popd )

Once again, I apologize for the previous bad code. Regards, Joe
0
coerraceAuthor Commented:
joe winograd I used your line and appears is bad formatted say:
do was unexpected at this time and like that if you make work sure go to search in subdirectories? Looks great I changed the IN DO (.) by IN (.) DO and does more but I see not go to inside sub directories to conver the files the error say:

mogrify: unable to open image `*.pdf': Invalid argument @ error/blob.c/OpenBlob/
2587.

   And that means is looking inside c:\data but not inside the subdirectories could you check I like mogrify.

duncanb7 why you use the del command? if it is just convert? don't want to destroy any data is a server.
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Our messages just crossed. See the code in my last post. I tested it and it works fine. But I had my own test folder in there (d:\0tempd\test\). Of course, change it to yours (c:\data\) — so you want:
FOR /R "c:\data\" %%I in (.) DO (
 Pushd %%I
 mogrify -format jpg *.pdf
 Popd )

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
duncanb7Commented:
del command , just delete junk.txt temp file only after finishing all convert, that file
is not related to convert

I have checked the script is working I used "copy" to simulate "convert" effect

Duncan
0
coerraceAuthor Commented:
Both scripts worked is just needed to run in my case in c:\ if I run from c:\temp for example not work but from c:\ all perfect.
Thank you
0
Joe Winograd, Fellow&MVEDeveloperCommented:
> if I run from c:\temp for example not work

Hmmm, I don't understand that. I haven't tried Duncan's solution, but I can tell you that mine should work fine running from c:\temp (in my test, I used d:\0tempd\test and it worked fine). In any case, you're welcome — and I'm glad you got it working! Regards, Joe
0
coerraceAuthor Commented:
I opened this new question just for a modification if you can help there:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28487736.html

Thank you
0
Joe Winograd, Fellow&MVEDeveloperCommented:
I'm leaving my office now for around 3-4 hours. I'll look at your new question as soon as I return. Regards, Joe
0
duncanb7Commented:
thx for your pt

ve a nice day

duncan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.