Is there a way to use "rsvg-convert" to convert either a multi page SVG or multi SVG files to a single multi page PDF?
I am using the command:
/usr/bin/rsvg-convert -f pdf -o out.pdf in.svg
you can provide a list of .svg files when converting to pdf.
rsvg-convert -f pdf -o out.pdf file1.svg file2.svg file3.svg
alternatively you can convert all .svg files in a folder to 1 pdf like this:
rsvg-convert -f pdf -o out.pdf *.svg
rsvg-convert
accomplishes a multi-SVG to single-PDF task see @holger-will's answer. However, it resizes all of the PDF pages to the same size as the first SVG file (regardless if the second, third, etc. are larger). This is not suitable for combining an assortment of varied SVGs which have different heights and widths.
An alternative -- svgstopdf
-- is available on Debian-based systems at https://github.com/pimpreneil/svgstopdf and ported to Windows at https://github.com/flueterflam/svgstopdf
Syntax is similar also:
svgstopdf file1.svg file2.svg (...) out.pdf
or
svgstopdf *.svg out.pdf
The benefit of using svgstopdf
is that every PDF page is exactly the size of the corresponding SVG image. You do not need to resize all your SVGs to a uniform width or height! Nor will subsequent SVGs be clipped, if the first one is smaller.
Although the OP asks for rsvg-convert
, please note that this method accomplishes the same task. Future users who find this question may be interested to learn of alternatives without the inherent restriction of rsvg-convert
(as of August 2018). This is very clear on lines 244-245 of rsvg-convert.c
of librsvg
see https://github.com/brion/librsvg/blob/master/rsvg-convert.c:
/* in the case of multi-page output, all subsequent SVGs are scaled to the first's size */
rsvg_handle_set_size_callback (rsvg, rsvg_cairo_size_callback, &dimensions, NULL);
Although it says "scaled" in the comment, my tests with using rsvg-convert
indicate that the subsequent PDF pages are sized to be the same as the first. Furthermore, the subsequent SVGs are not resized to fit the PDF page but rather clipped. So the "scaling" process is referring to the PDF page and not the SVG image.
An example of this is by taking the two SVG files: 128px x 128 px - https://en.wikipedia.org/wiki/File:Blue_sphere.svg 288px x 288px - https://www.shareicon.net/download/2015/10/03/111553_wifi.svg
Using rsvg-convert -f pdf -o out.pdf Blue_sphere.svg 111553_wifi.svg
, the resulting PDF looks like this:
(page 1)
(page 2)
Obviously, this is not the desired outcome. Instead, using svgstopdf.exe Blue_sphere.svg wifi.svg out2.pdf
results in:
(page 1)
(page 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With