Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Default SVG

Probably the most basic use of the module is to generate an SVG image without any content.

After loading the module we create an instance using the new method and then render the SVG using the xmlify method.

You can print the resulting string to the screen as we do in this example or you could have saved it in a file directly. It all depends on your use-case.

use strict;
use warnings;
use SVG;

my $svg= SVG->new();
print $svg->xmlify();

The generated SVG looks like this: (I added some newlines to make the lines shorter to fit on the page).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
   "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg height="100%" width="100%"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink">
	<!--
	Generated using the Perl SVG Module V2.87
	by Ronan Oger

	-->
</svg>

It has a lot of text besides what is strictly necessary.

There are the xml and DOCTYPE tags

The svg tag has xmlns, xmlns:svg, xmlns:xlink fields besides height and width.

After that there is a comment with the giving credit to the Perl module and the original author of the module.

You can keep these or you can make the SVG file a bit smaller by removing some of the unnecessary parts.