Posts Tagged ‘extract’

How to extract a deb package on Debian, Ubuntu, Mint Linux and other non debian based distributions

Friday, October 13th, 2017

how-to-extract-deb-packages-with-dpkg-and-ar-application-x-deb

How to extract a deb package? 


Have you ever had a debian .deb package which contains image files you need, but the dependencies doesn't allow you to install it on your Debian / Ubuntu / Mint Linux release?
I had just recently downloaded the ultimate-edition-themes latest release v 0.0.7 a large pack of GNOME Themes and wanted to install it on my Debian Stretch Linux but I faced problems because of dependencies when trying to install with dpkg.

That is why I took another appoarch and decided to only extract the necessery themes from the archive only with dpkg.

Here is how I have extracted ultimate-edition-themes-.0.0.7_all.deb ;

 

dpkg -x ultimate-edition-themes-.0.0.7_all.deb /tmp/ultimate-edition-themes

 

 

So how dpkg extracts the .deb file?

 


Debian .deb packages are a regular more in Wikipedia – Unix archive files (ar) .

The structure of a deb file consists of another 3 files (2 tar.gzs and one binary) as follows:

 

debian-binary: regular text file, contains the version of the deb package format
control.tar.gz: compressed file, contains file md5sums and control directory for the deb package
data.tar.gz: compressed file, contains all the files which will be installed


Basicly if you're on a Linux distribution that lacks dpkg you can easily extract .deb binary using GNU AR  command (used to create, modify extract Unix ar files and is the GNU / Linux equivallent of the UNIX ar command).

To extract on Fedora or RPM based Linux distributions as well as BSDs with AR:

First print file conetnt with:

ar p  ultimate-edition-themes-.0.0.7_all.deb

Then extract it with:

ar x ultimate-edition-themes-.0.0.7_all.deb

 


Later just extract with tar (untar), the 2 other archived files contained in the .deb (ar) archive:

 

 

tar -zxvvf control.tar.gz; tar -zxxvf data.tar.gz

 


Get everything you need from there in my case that's the usr/share/themes folder, then enjoy life 🙂

 

Save ( Extract ) only images from PDF files on GNU / Linux in console and in GNOME nautilus

Wednesday, November 14th, 2012

extract only pictures / ( images ) from PDF / PDF save only images

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 "Скриптове" 🙂

nautilus scripts menu screenshot - allowing users to add custom shell scripts to run in GNOME desktop extract pictures from PDF Linux

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.

Download the following extract_images_from_pdfs.sh shell script

$ 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
#!/bin/bash
# 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
# https://www.pc-freak.net/blog/
if [ $1 ]; then
if [ ! -d ./$1_images ]; then
mkdir -p ./"$1_images"
fi
pdfimages -j "$1" ./"$1_images"/PDFimage
gdialog --title "Report" --msgbox "Images were successfully extracted!"
exit 0
fi

 

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.

I've learned about pdfimages existence from Sven Boekhoff's blog which btw has plenty of interesting other stuff

 

Well that's it hope this helps, someone. Comments are welcome 🙂