Some time ago, I've blogged how it is possible to dump a PDF individual pages into JPG / PNG etc. pics.
Today interestingly, I've learned it is possible to not only dump single or whole PDF document pages into pictures but also to selectively dump only the pictures contained within PDF file into JPEGs.
Dumping only PDF (contained) images into external JPEG files is doable on GNU / Linux with pdfimages.
1. Extracting pictures from PDF in text console / terminal
pdfimages is part of poppler-utils deb package, if for some reasons you don't have pdfimages on ur system install poppler-utils with;
apt-get install --yes poppler-utils
To extract images of a certain PDF from terminal / console command line it is as simple as:
pdfimages -j pdf-file-name.pdf prefix-of-output-file
pdfimages will extract all pictures, but bear in mind with some PDF versions it might incorrectly dump some text pages thinking it is pictures too. Also with some PDFs which contain scanned very old paper documents (as pictures) trying to force pdfimages to dump it will just provide you with all pages of the PDF in JPGs. Option -j instructs dumping images from PDF in JPEG picture format, whether the second argument will save pictures in files like: prefix-of-output-file-000.jpg, prefix-of-output-file-001.jpg, prefix..-file-002.jpg etc.
2. Adding GNOME nautilus capability to extract images from PDF files
Enabling extracting images in nautilus is possible with one non-default nautilus plugin nautilus-scripts-manager
nautilis-scripts-manager is very nice, but I'm sure many Linux users did not know it yet. It makes possible to add any custom shell script that does an opeartion to be visible in nautilus via one extra menu Scripts. As not normally needed on most Linux distributions, it is not installed by default so you have to install it:
noah:~# apt-get install --yes nautilus-scripts-manager …
Below is a Screenshot from my nautilus Scripts menu (my locale is in Bulgarian), so Scripts word is in Cyrillic "Ð¡ÐºÑ€Ð¸Ð¿Ñ‚Ð¾Ð²Ðµ" 🙂
After nautilus-scripts-manager is installed. To use it in your user home directory you will have to create ~/.gnome/nautilus-scripts, i.e.
$ mkdir ~/.gnome2/nautilus-scripts
Any script placed inside can be then invoked via the newly appeared nautilus "Scripts" menu. Thus to use extract_images_from_pdfs.sh from GUI place it there.
$ cd ~/.gnome2/nautilus-scripts
$ wget -q https://www.pc-freak.net/files/extract_images_from_pdfs.sh
$ chmod +x extract_images_from_pdfs.sh
If you prefer to copy paste script content:
$ cat ~/.gnome2/nautilus-scripts/extract_images_from_pdf.sh
# Extracts image files from PDF files
# For more information see www.boekhoff.info
## Added check for $1 existence and $1_images dir
existence check by hip0
if [ $1 ]; then
if [ ! -d ./$1_images ]; then
mkdir -p ./"$1_images"
pdfimages -j "$1" ./"$1_images"/PDFimage
gdialog --title "Report" --msgbox "Images were successfully extracted!"
Well that's all. Once you select a PDF and you click with last mouse button on it selecting Scripts -> extract_images_from_pdf.sh a new directory containing the filename prefix of the selected PDF with _images will appear. For exmpl. if pictures are extracted from PDF named filename.PDF in same directory where the file is present you will get new filename_images folder with all pictures dumped from the PDF.
Well that's it hope this helps, someone. Comments are welcome 🙂