Extract all images in PDF file in a directory (batch extract images)

Focus On Content  ~/ click me to toggle the navigation bar to the right

Sometimes you need a way to extract all images in a PDF but then you have a directory of files and you need to extract them iteratively.

Prerequisites:

  1. Install Cygwin or linux environment with Perl support.

  2. Install ImageMagick .

  3. Install GhostScript .

Afterward run the following script:

[sourcecode language=“jscript”]

#!/bin/perl

my $directory = $ARGV[0]; opendir (DIR, $directory) or die $!; while (my $file = readdir(DIR)) { if ($file =~ m/.pdf/) { my $newfile = $file; $newfile =~ s/.pdf/_%01d.jpg/; print “Processing " . $file . " ; newfilename: " . $newfile . “…\n”; convert -density 150 $file $newfile; } }

[/sourcecode]

How to invoke: scriptname path_to_pdf_files

Cheers.