Alternativ kann man mit der FFI von LuaTeX ≥ 1.0.3 oder LuaJITTeX und pplib das SVG direkt mit Cairo und RSVG2 rendern, siehe meine Antwort auf TeX.SX https://tex.stackexchange.com/a/408014
<code><pre>
lualatex --shell-escape test.tex
\# oder
luajittex --fmt=luajitlatex --shell-escape test.tex
</pre></code>
MWE:
\documentclass{article}
\usepackage{luacode}
\begin{luacode}
local ffi = require("ffi")
ffi.cdef[[
// Types
typedef void FILE;
typedef void GError;
typedef void RsvgHandle;
typedef void cairo_surface_t;
typedef void cairo_t;
typedef int(*cairo_write_func_t)(void *, const unsigned char *, unsigned int);
typedef struct {
int width;
int height;
double em;
double ex;
} RsvgDimensionData;
// Conversion functions
RsvgHandle * rsvg_handle_new_from_file(const char *, GError **);
void rsvg_set_default_dpi_x_y(double, double);
int rsvg_handle_get_dimensions(RsvgHandle *, RsvgDimensionData *);
cairo_surface_t * cairo_pdf_surface_create_for_stream(cairo_write_func_t, FILE *, double, double);
cairo_t * cairo_create(cairo_surface_t *);
void cairo_scale(cairo_t *, double, double);
int rsvg_handle_render_cairo(RsvgHandle *, cairo_t *);
// Cleanup functions
void cairo_destroy(cairo_t *);
void cairo_surface_destroy(cairo_surface_t *);
void g_object_unref(void *);
]]
local lcairo = ffi.load("cairo")
local lrsvg = ffi.load("rsvg-2")
function svg_to_pdf(params, filename)
-- Open input file
local err = ffi.new("GError**", nil)
local rsvg = lrsvg.rsvg_handle_new_from_file(filename, err)
-- Get size of image
local dimensions = ffi.new("RsvgDimensionData[1]")
lrsvg.rsvg_handle_get_dimensions(rsvg, dimensions)
local width = params.scale * dimensions[0].width
local height = params.scale * dimensions[0].height
-- Open cairo PDF canvas of same size and associate callback function
local output = ""
function rsvg_cairo_write_func(_, data, length)
output = output .. ffi.string(data, length)
return 0 -- CAIRO_STATUS_SUCCESS
end
local surface = lcairo.cairo_pdf_surface_create_for_stream(
rsvg_cairo_write_func, nil, width, height);
-- Render SVG on the canvas
local cr = lcairo.cairo_create(surface)
lcairo.cairo_scale(cr, params.scale, params.scale);
lrsvg.rsvg_handle_render_cairo(rsvg, cr)
-- Clean up
if (cr ~= nil) then lcairo.cairo_destroy(cr) end
if (surface ~= nil) then lcairo.cairo_surface_destroy(surface) end
if (rsvg ~= nil) then lrsvg.g_object_unref(rsvg) end
if (err ~= nil) then lrsvg.g_object_unref(err[0]) lrsvg.g_object_unref(err) end
return output
end
\end{luacode}
\newcommand\includesvg[2][scale=1]{%
\leavevmode
\luaexec{
local stream = svg_to_pdf({#1},[[#2]])
local identifier
if status.luatex_version < 108 then
_, identifier = epdf.openMemStream(stream,\#stream,[[#2]])
else
identifier = pdfe.new(stream,\#stream,[[#2]])
end
node.write(img.node { filename = identifier })
}%
}
\begin{document}
\includesvg[scale=.3]{flag.svg}
\end{document}