Skip to contents

Convert an SVG string or SVG file path to a vector PDF. As with svg_to_png(), the SVG is sanitized and the required WOFF2 fonts are embedded (downloaded on demand into a user cache) so text renders consistently. Conversion uses rsvg (rsvg::rsvg_pdf()), preserving vector text.

For headless-Chrome rendering (often best for web fonts), see svg_to_pdf_chrome().

Usage

svg_to_pdf(svg_input, output_path = NULL, width = NULL, height = NULL)

Arguments

svg_input

SVG string or path to an SVG file.

output_path

Output path for the PDF file (optional; a temp file is used if NULL).

width

Output width in pixels (NULL to infer from the SVG).

height

Output height in pixels (NULL to infer from the SVG).

Value

Path to the generated PDF file.

Examples

if (requireNamespace("rsvg", quietly = TRUE)) {
  svg <- svg_card("FAR", list(), list())
  file_name <- tempfile(fileext = ".pdf")
  pdf_path <- svg_to_pdf(svg, file_name)
}