Converting pdf to jpg in multiple directories? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Converting pdf to jpg in multiple directories?

UNIX for Dummies Questions & Answers


Tags
imagemagick, linux, shell bash, solved

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-12-2013
martinsmith martinsmith is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 13 January 2013, 3:03 PM EST
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Ubuntu [Solved] Converting pdf to jpg in multiple directories?

Hi!

On my Ubuntu I have thousands of files in a couple hundred directories. I'm trying to convert the pdf's to jpg's.

I used this command in terminal:

Code:
for fname in *.pdf; do convert $fname ${fname%.pdf}.jpg; done

It works great but the problem is I have to run this in terminal for each folder/directory so it's time consuming.

Is it possible to covert all the pdf's in the sub directories from the root directory at once in terminal?

Thanks for your help

Moderator's Comments:
Please use code tags next time for your code and data.

Last edited by radoulov; 01-13-2013 at 03:36 PM.. Reason: Marked as solved.
Sponsored Links
    #2  
Old 01-13-2013
pen pen is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 13 January 2013, 9:37 AM EST
Location: Helsinki, Finland
Posts: 32
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by martinsmith View Post
Hi!

On my Ubuntu I have thousands of files in a couple hundred directories. I'm trying to convert the pdf's to jpg's.

I used this command in terminal:
for fname in *.pdf; do convert $fname ${fname%.pdf}.jpg; done

It works great but the problem is I have to run this in terminal for each folder/directory so it's time consuming.

Is it possible to covert all the pdf's in the sub directories from the root directory at once in terminal?

Thanks for your help
Hi,

use find - you can traverse your directories with it, and even start your conversion per each file found. There are more efficient methods, but this depends on the amount of the files you have. Have a look at the manual page of find(1), but one way to accomplish your target would be something like:

Code:
find the_root_directory_of_pdfs -name \*.pdf -exec convert \{\} \{\}.jpg \;

The {} marks the filename found, and because of the shell the braces have to be escaped, as well as the command-ending semicolon.

There are also other, more CPU-friendly methods, but this may serve as a one-time solution.

BR,

pen

EDIT: Umm, I just noticed you want the change the filename extention for good - my solution leaves file names as foo.jpg.pdf... With find, this would work:

Code:
find root_of_pdfs -name \*.pdf | while read fname; do convert $fname ${fname%.pdf}.jpg; done


Last edited by pen; 01-13-2013 at 09:30 AM.. Reason: See section EDIT...
The Following User Says Thank You to pen For This Useful Post:
martinsmith (01-13-2013)
Sponsored Links
    #3  
Old 01-13-2013
martinsmith martinsmith is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 13 January 2013, 3:03 PM EST
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pen View Post
Hi,


EDIT: Umm, I just noticed you want the change the filename extention for good - my solution leaves file names as foo.jpg.pdf... With find, this would work:

Code:
find root_of_pdfs -name \*.pdf | while read fname; do convert $fname ${fname%.pdf}.jpg; done

Hi Pen,

Yes Thanks you this is exactly what I needed!
It's worked perfectly after testing and done the conversion of all the pdf files to jpg.

Thanks very much for your help, I appreciate it!

Bets Regards
Martin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Create a dummy file in all directories that include a .jpg Davinator Shell Programming and Scripting 11 04-03-2012 06:12 PM
Converting EPS to JPG issue rlopes UNIX for Dummies Questions & Answers 0 01-11-2012 07:41 PM
Converting multiple latex files to pdf Element9 UNIX for Dummies Questions & Answers 2 01-09-2009 12:10 PM
AIX converting PDF to PS vinayakshukre AIX 3 12-11-2008 05:14 AM
PDF/EPS to GIf/JPG Help!! PookJP UNIX for Dummies Questions & Answers 1 06-26-2001 06:45 PM



All times are GMT -4. The time now is 02:39 AM.