Posts Tagged ‘Scalable’

Convert single PDF pages to multiple SVG files on Debian Linux with pdf2svg

Sunday, February 26th, 2012

In my last article, I've explained How to create PNG, JPG, GIF pictures from one single PDF document
Convertion of PDF to images is useful, however as PNG and JPEG graphic formats are raster graphics the image quality gets crappy if the picture is zoomed to lets say 300%.
This means convertion to PNG / GIF etc. is not a good practice especially if image quality is targetted.

I myself am not a quality freak but it was interesting to find out if it is possible to convert the PDF pages to SVG (Scalable Vector Graphics) graphics format.

Converting PDF to SVG is very easy as for GNU / Linux there is a command line tool called pdf2svg
pdf2svg's official page is here

The traditional source way compile and install is described on the homepage. For Debian users pdf2svg has already existing a deb package.

To install pdf2svg on Debian use:

debian:~# apt-get install --yes pdf2svg
...

Once installed usage of pdf2svg to convert PDF to multiple SVG files is analogous to imagemagick's convert .
To convert the 44 pages Projects.pdf to multiple SVG pages – (each PDF page to a separate SVG file) issue:

debian:~/project-pdf-to-images$ for i in $(seq 1 44); do \
pdf2svg Projects.pdf Projects-$i.SVG $i; \
done

This little loop tells each page number from the 44 PDF document to be stored in separate SVG vector graphics file:

debian:~/project-pdf-to-images$ ls -1 *.svg|wc -l
44

For BSD users and in particular FreeBSD ones png2svg has a bsd port in:

/usr/ports/graphics/pdf2svg

Installing on BSD is possible directly via the port and convertion of PDF to SVG on FreeBSD, should be working in the same manner. The only requirement is that bash shell is used for the above little bash loop, as by default FreeBSD runs the csh. 
On FreeBSD launch /usr/local/bin/bash, before following the Linux instructions if you're not already in bash.

Now the output SVG files are perfect for editting with Inkscape or Scribus and the picture quality is way superior to old rasterized (JPEG, PNG) images

How to convert SVG to PNG graphic formats (using GUI and console) on GNU / Linux and FreeBSD

Wednesday, December 7th, 2011

SVG to PNG Convert on GNU / Linux FreeBSD using command and GUI

I’ve playing trying to learn InkScapeThe Open Source vector graphic editor .By so far I’m quite impressed on how easy this program is learned and how easy graphical manipulation with this nifty program can be done.
The default format in which InkScape saves its files is SVG (Scalable Vectors Graphics). For all those unfamiliar with SVG – SVG is an open (free format) format developed in 1999 which insetad of containing binary data like PNG or JPEG does contain plain XML content. SVG being consisted of plain XML has multiple advantageous, the most important one makes it easy for text and visual data to be displayed among different program svg readers in absolutely identical way. Besides that the format if read with plain text editor like vim or emacs can be altered directly via the source.
Being multi system interoperable makes SVG as a great format for text and visual data storage in HTML5, actually SVG is already a part of the HTML5 html coding standard. And most probably its adoption rate will raise up drastically as soon as HTML5 starts substitute HTML4 and lower web standards.

Anyways I’m slipping away from the aim of this post so I’ll stop blabbering on how great SVG is and let people check it out for themselves (if not already).

Going back to the aim of my article to show How to convert SVG to PNG graphical extension on GNU / Linux and FreeBSD

After producing a bunch of files with InkScape I realized the default format in which Inkscape stores its files is SVG , this was okay with me but since I wanted to have my experimental produced content in PNG I needed a way to convert SVG to
My first logical guess was that The Gimp will be able to handle the situation and after opening my SVG file with GIMP and used the gimp File -> Save As option and give the SVGfile an extension of PNG , Gimp succesfully converted the file to PNG.

However I wanted to dig further and check out what is the standard accepted way to convert SVG files using a plain command. This will possibly be handy to me if I had to do something online (let’s say a website) which will accept SVG and will require the SVG files to be converted and also stored in PNG or other Graphic file formats.

After checking online, I’ve found a post which pointed me to librsvg2 which contains RSVG(Turn SVG files into raster images.)

librsvg is available as a package in most mainstream Linux distributions nowdays, Fedora, Debian etc., as well as contains a port inside the FreeBSD ports system. Since I’m using Debian on my notebook where I installed and tested the command line SVG to PNG convertion the way I did it is:

noah:/home/hipo/Desktop# apt-get --yes install librsvg2-bin
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
librsvg2-bin
0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded.
Need to get 72.5 kB of archives.
After this operation, 180 kB of additional disk space will be used.
Get:1 http://ftp.nl.debian.org/debian/ squeeze/main librsvg2-bin amd64 2.26.3-1 [72.5 kB]
Fetched 72.5 kB in 0s (184 kB/s)
Selecting previously deselected package librsvg2-bin.
(Reading database ... 376046 files and directories currently installed.)
Unpacking librsvg2-bin (from .../librsvg2-bin_2.26.3-1_amd64.deb) ...
Processing triggers for man-db ...
Setting up librsvg2-bin (2.26.3-1) ...

Afterwards the exact convertion of my Inscape SVG file drawing.svg to drawing.png using rsvg I’ve done like so:

hipo@noah:~/Desktop$ rsvg drawing.svg drawing.png

The convertion results for me was 100% uniqueness between the file converted and the output PNG. Some people might wonder why I didn’t used Inkscape’s Export to Bitmap function and then use convert command part of ImageMagick in order to convert the produced Inkscape bitmap to PNG.

 

One other thing worthy to mention is on  Debian,  librsvg2-bin contains 2 more executable besides rsvg. One is the rsvg-view command which allows one to view SVG files using command line or Graphic enviroment, the other one is rsvg-convert which supports again SVG convertion to PDF and to PNG

Before proceeding with the other described ways to convert SVG to PNG earlier in this article, I give a try to Inkscape’s Export to Bitmap embedded function but the produced bitmap did not resembled the original SVG file so I decided to completely abandon this method
Maybe there is some particular reason of the chaotic way I’ve tested Inkscape to place random images sometimes going out of the field of a paper etc. which influenced the improper generation of Bitmap using Inkscape, despite that it seems InkScape needs some more development until the bugs in Bitmap producing get fixed and it can be freely used to produce Bitmaps.

Maybe there is some particular reason for the failure of Inkscape to produce a good BMP file, like for example the chaotic way I’ve tested Inkscape to place random images sometimes going out of the field of a paper borders etc.This should have influenced the improper generation of Bitmap using Inkscape, anyhow it seems InkScape needs some more development until the bugs in Bitmap creation get fixed.

By the way if you’re wondering how to convert PNG to bitmap BMP after, once having converted SVG to PNG this is easily doable with convert command, like so:

hipo@noah:~/Desktop$ convert drawing.png drawing.bmp

Maybe in future releases it will be a good idea if InkScape developers integrate a convertion to other formats this will make it handy and make surely these nice program more popular among users. Hope this is helpful. Cheers and as RMS likes to say Happy Hacking 😉