Converting pdf to jpg in multiple directories?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Converting pdf to jpg in multiple directories?
# 1  
Old 01-13-2013
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:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 01-13-2013 at 04:36 PM.. Reason: Marked as solved.
# 2  
Old 01-13-2013
Quote:
Originally Posted by martinsmith
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 10:30 AM.. Reason: See section EDIT...
This User Gave Thanks to pen For This Post:
# 3  
Old 01-13-2013
Quote:
Originally Posted by pen
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! Smilie
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create pdf of a jpg image in shell script

Dear Team, Can any one please let me know, if there is any way to create pdf of a Jpg image file in shell script. I work on Solaris, Korn Shell. Currently we are using sunpcl2pdf.exe to create PDF from PCL(Printer Control Language) files. But we are searching for some different way to... (2 Replies)
Discussion started by: Uttam Maji
2 Replies

2. Shell Programming and Scripting

Converting secured pdf files to pdf using acroread

Does anybody have idea of Converting secured pdf files to pdf using acroread ? ---------- Post updated at 04:49 PM ---------- Previous update was at 04:44 PM ---------- This file is not password protected. (4 Replies)
Discussion started by: Soham
4 Replies

3. Shell Programming and Scripting

Create a dummy file in all directories that include a .jpg

Hello. My latest project has me with the need for the following script. Basically, any directory that includes a .jpg file needs to also have a ".picture" file created (if it doesn't exist). Here's an example of what I need. /mnt/user/Pictures/2011/Hawaii - 2011/.picture... (11 Replies)
Discussion started by: Davinator
11 Replies

4. UNIX for Dummies Questions & Answers

Ghostscript error while converting PDF to Postscript

Hi, I have been using Ghostscript to convert PDF to Postscript (PS) file. GS version : 8.15.2. GS command used is : gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pswrite -sOutputFile=output1.ps input1.pdf File format conversion to PS is success in majority of the cases but some PDF files are... (0 Replies)
Discussion started by: geeveejey
0 Replies

5. UNIX for Dummies Questions & Answers

Converting EPS to JPG issue

I'm trying to convert a file with the following command: convert -verbose image.eps -resize 500x image.jpg The problem is that the output image loses it's quality and gets all blurred when resized. It shouldn't happen since I'm working with a vector. I'm pretty sure that I'm missing a... (0 Replies)
Discussion started by: rlopes
0 Replies

6. Shell Programming and Scripting

Converting html to pdf perl

Hi All, I have a requirement of converting an html form into pdf using perl. The html form contains images, tables and css implementation. I tried using various perl modules but failed to achive the target. I succeeded in generating a pdf from the html file using... (2 Replies)
Discussion started by: DILEEP410
2 Replies

7. UNIX for Dummies Questions & Answers

Converting multiple latex files to pdf

Hi everybody! This is my first post. I am a student and I'm familiarizing myself with linux. I have lots of directories each containing file called "zadaci.latex". I want to convert them to pdf's and rename them to <directory_name>.pdf. I read alot on this forum and came up with this script:... (2 Replies)
Discussion started by: Element9
2 Replies

8. AIX

AIX converting PDF to PS

my app creates pdf and prints them on windows. I want to run the same app on AIX 5.2. I convert PDF to PS using acroread command. But some options of acroread like landscape etc do not work. I came to know from google that there is bug with acroread for AIX with landscape option. Can you suggest... (3 Replies)
Discussion started by: vinayakshukre
3 Replies

9. Shell Programming and Scripting

Converting ps file to pdf

I have a number of post script files (*.ps) which I need to convert into Pdf. I am using the ps2pdf command for this, but the trouble is that this commands takes only one input at a time. So the command ps2pdf *.ps doesnt work. how can I make a script which will take each .ps file from... (3 Replies)
Discussion started by: jasjot31
3 Replies

10. UNIX for Dummies Questions & Answers

PDF/EPS to GIf/JPG Help!!

Hello. I have a large number of EPS files and a lesser number of PDFs that I need to convert to GIFs/JPGs using a Unix system. Is there a unix utility or application out there that can do this conversion? Thank you in advance for any help you can provide. -Pook (1 Reply)
Discussion started by: PookJP
1 Replies
Login or Register to Ask a Question