4

In Ubuntu 16.04 LTS, I use pdftoppm to convert pdf files to png files one by one like the code given below:

pdftoppm -rx 300 -ry 300 -png XYZ.pdf XYZ

However, I have to convert many pdf files to png files. I wonder if it is possible to convert many pdf files to png files with single command like

pdftoppm -rx 300 -ry 300 -png *.pdf *

Any help will be highly appreciated. Thanks

MYaseen208
  • 663
  • 4
  • 17
  • 32

1 Answers1

6

You can use simple for loop:

#!/bin/bash

for i in *.pdf; do
   pdftoppm -png -rx 300 -ry 300 $i ${i%.pdf*}
done
EdiD
  • 4,327
  • 3
  • 23
  • 40
  • Thanks @EdiD for your answer. Do I need to use this command in Ubuntu Terminal? – MYaseen208 Sep 08 '16 at 09:35
  • 1
    @MYaseen208 This is a script. Make a file (in folder where your pdfs are located) with this content, give executive rights (`chmod u+x yourfile.sh`) for file and launch it in this way: `./yourfile.sh` – EdiD Sep 08 '16 at 15:51
  • 1
    @MYaseen208 and yes off course this is executable from terminal – EdiD Sep 08 '16 at 16:06
  • 1
    Thanks @EdiD for your useful answer. First need to move the folder, `chmod a+x yourfile.sh` and `./yourfile.sh` did the trick. Thanks – MYaseen208 Mar 26 '17 at 14:05
  • 1
    You can also copy this into a terminal and then press ENTER (after you cd into the directory). – mchid Aug 02 '19 at 01:32