PDF::Bu...age::SVG(3)
π NAME π
PDF::Builder::Resource::XObject::Image::SVG β support routines for the SVG (Scalable Vector Graphics) image library π¦
(You've landed in the PDF::Builder::Resource::XObject::Image::SVG(3) page, from the User Contributed Perl Documentation. Welcome, bestie π )
It inherits from PDF::Builder::Resource::XObject::Image β family tree matters, okay?
β οΈ Okay so here's the one thing that makes this module different from literally every other image format: unlike the output of other image formats,image_svg()returns an array of anonymous hashes, one for each<svg>tag inside your SVG input. That's just the vibe. Full deets in "What is returned" down below π
β¨ METHODS β¨
π new
$res = PDF::Builder::Resource::XObject::Image::SVG->new($pdf, $file, %opts)
$file is your SVG input (peep the SVGPDF library for the details and limitations, fr fr). It can be any one of these three things:
- a filename π
- a string reference (with SVG content inside it) π§΅
- a filehandle π§
π Options π
subimage => nβ if your SVG file has multiplesvgentries and they are not combined by SVGPDF'scombineoption into one image, this lets you pick which image to display. Anyngoes, from0up to the number ofsvgimages minus 1. The n-th element gets retained, and all the others get discarded. The default is to return the entire array and remove nothing, which lets you display multiple images in whatever order you want. See the whole discussion on combining multiple images in "Dealing with multiple image objects, and combining them". The default behavior of the display routine (object) is to display only the first element (and there has to be at least one, periodt).MScore => flagβ set it true (a non-zero value) and a font callback for the 14 Microsoft Windows "core" extensions gets added to whatever other font callbacks the user gave. Those include"Georgia"serif,"Verdana"sans-serif, and"Trebuchet"sans-serif fonts, plus the"Wingdings"and"Webdings"symbology fonts. Non-Windows systems usually don't include these "core" fonts, so it may be unsafe to use them, ngl.
This option is enabled for all operating systems, not just MS Windows, so you can create PDFs that make use of Windows "core" fonts (extension). But this does not guarantee those fonts will be available on the machine used to read the resulting PDF! π
compress => flagβ set it true (a non-zero value; default is1) and the resulting XObject stream gets compressed. That's what you'd normally do, obviously. Set it false (0) and the stream is left uncompressed instead. You might want that if you're trying to examine the stream in the finished PDF, like the t-test does. π
π SVGPDF Options π
These are options which, if given, get passed on to the SVGPDF library. Some of them are fixed by image_svg and can not be changed, while others are defaulted by image_svg but can be overridden by you. Go consult the SVGPDF library documentation for more details on these, bestie.
pdf => PDF objectβ automatically set by the SVG routine, and it can not be overridden by the user. It gets passed toSVGPDF->new().fontsize => nβ the font size (in points) for SVGPDF to use to scale text and figure the em and ex sizes. Default is12points. Passed on to both theSVGPDF->new()and$svg->process()SVGPDF methods.pagesize => [ width, height ]β the maximum dimensions of the resulting object, in case there are no dimensions given, or they're too large to display. Default is595 pt x 842 pt(A4 page size), internal to SVGPDF. Passed toSVGPDF->new().grid => nβ default is0. A value greater than0indicates the spacing (in points) of a grid, for development/debugging purposes. Passed toSVGPDF->new().verbose => nβ defaults to0(fatal messages only), but you can crank it higher to get informational messages out. Passed toSVGPDF->new().fc => \&fonthandler_callbackβ a list of one or more callbacks for the font handler. If theMScoreflag is true (see above), another callback gets added to the list to handle MS Windows "core" font faces. Passed toSVGPDF->new().
Note that some supporting packages, such as GnuPlot, make use of Windows fonts such as Arial, which may or may not be installed on non-Windows platforms β and even for Windows, they'd need to be added to FontManager. You should check the resulting SVG files produced by Third-Party packages to see what fonts they're expecting. MathJax creates text characters as filled outlines in SVG, and does not appear to use any standard fonts.
combine => 'method'β if an SVG defines multiple XObjects (because of multiplesvgentries), they may be combined into a single XObject. Default is none, which does not combine XObjects. Currently the only other supported method isstacked, which vertically stacks images withsepspacing between them. At this writing, thebboxcombine method is not supported by SVGPDF, but it may be in the future. Passed to$svg->process().sep => nβ vertical space (in points) to add between individual images whencombineis not'none'. Default is0(no space between images). Passed to$svg->process().
π¦ What is returned π¦
Returns an image in the SVG. But unlike other image formats, it's not actually some form of image object β it's an array (of at least one element) containing XObjects of the SVG converted into PDF graphics and text commands. If an SVG includes a pixel-based image, that image gets scaled up and down the normal image way, while PDF graphics and text are always fully scalable β both when setting an image size and when zooming in and out in a PDF Reader. π
A returned object is always an array of hashes (including the XObject as one of the elements), one per svg tag. And note that svgs must be peers (top-level), and may not be nested one within another! π In most applications, an SVG file will have one svg tag and therefore a single element in the array. However, some SVGs will produce multiple array elements from multiple svg tags.
π Dealing with multiple image objects, and combining them π
If you don't set subimage, the full array gets returned. If you set subimage => n, where n is a valid element number (0...), all elements except the n-th get discarded, leaving a single-element array. When it comes time for object() to display this XObject array, the first (0th) element gets displayed and any other elements are ignored. So the default behavior is effectively subimage => 0. You may call either object or image β image will simply pass everything on to object.
Remember that not setting subimage causes the entire array to be returned. You're free to rearrange and/or subset this array if you wish. If you want to display multiple images (in the PDF), you can select one or more of the array elements to be processed (see the examples). If you want to stack all of them vertically, maybe with some space between them, consider using the combine => 'stacked' option β but be aware that the total height of the single resulting image may be too large for your page! π You may need to output them separately, as many as will fit on a page.
That leaves the possibility of overlaying multiple images to overlap in one large combined image. You have the various width and height (and bounding box coordinates), so it's possible to align images to have the same origin. SVGPDF may get combine => 'bbox' at some point in the future to automate this, but for the time being you need to do it yourself. Keep an eye out for different svgs scaled at different sizes β they may need rescaling to overlay properly. π
π And that's the whole page, bestie. This one's from perl v5.42.0, dated 2026-01-17 β go forth and vector, no cap πβ¨
π¦ where this page comes from
- fedora 44: perl-PDF-Builder 3.028-2.fc44 Β· LGPL-2.1-or-later AND LGPL-2.1-only AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms