Extract all images in PDF file in a directory (batch extract images)
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:
-
Install Cygwin or linux environment with Perl support.
-
Install ImageMagick.
-
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.