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

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.

Venkatt Guhesan avatar
About Venkatt Guhesan
Enterprise Software Architect currently working at DataDirect Networks developing a highly scalable monitoring solution called DDN Insight. My passions include all things Open Source including Linux (CentOS, Red Hat, Gentoo, Open Stack, Docker & Ubuntu), embedded ARM processors and microcontrollers (Arduino, UDOO, Cubieboard, BeagleBoard, OnionIO, TI's Zigbee). Coming from an Electrical and Computer Engineering background, working in developing and designing enterprise - distributed, highly scalable software requires a unique set of software skills with a good understanding of the hardware. This makes his work challenging and interesting. In his free time, he spends his time with his family and two children. He also enjoys researching on topics including - world ancient history and yoga. Visit the 'About' section for more details.
comments powered by Disqus