Torsten Schoenfeld has posted the Perl interface to the Gnome Scalable Vector Graphics library... librsvg. Gnome2-Rsvg

You don't need the Gnome desktop to run this, but you may need a few Gnome libs, like libcroco, librsvg and the latest Cairo version. It displays SVG files, can zoom them, etc. This is a very basic example showing it's use.

#!/usr/bin/perl use strict; use warnings; use Gtk2 '-init'; use Gnome2::Rsvg; my $file = shift || die "Need and svg file as argument $!\n"; my $sw = Gtk2::ScrolledWindow->new(undef, undef); $sw->set_policy('automatic','automatic'); my $mw = Gtk2::Window->new; $mw->add($sw); my $vp; &load_image; $mw->signal_connect('destroy', sub { Gtk2->main_quit }); Gtk2->main; ########################################################## sub load_image { $sw->remove($vp) if defined $vp; # The easy way. my $pb = Gnome2::Rsvg->pixbuf_from_file_at_zoom_with_max($file,10,10,1 +000,1000); # ($file, x_zoom, y_zoom, max_x, max_y ) my $img = Gtk2::Image->new_from_pixbuf($pb); my ($x, $y) = ($pb->get_width, $pb->get_height); $vp = Gtk2::Viewport->new(undef, undef); $vp->add($img); $sw->add($vp); $mw->resize(500,500); my $ha = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); my $va = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); $sw->set_hadjustment($ha); $sw->set_vadjustment($va); $mw->set_title("$file ${x}x${y}"); $mw->show_all(); return 1; }

In reply to SVG viewer for Perl/Gtk2 by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.