pub fn to_pdf(
tree: &Tree,
conversion_options: ConversionOptions,
page_options: PageOptions,
) -> Result<Vec<u8>, ConversionError>
Expand description
Convert a usvg
tree into a standalone PDF buffer.
ยงExample
The example below reads an SVG file, processes text within it, then converts it into a PDF and finally writes it back to the file system.
use svg2pdf::usvg::fontdb;
use svg2pdf::{ConversionOptions, PageOptions};
use std::sync::Arc;
let input = "tests/svg/custom/integration/matplotlib/stairs.svg";
let output = "target/stairs.pdf";
let svg = std::fs::read_to_string(input)?;
let mut options = svg2pdf::usvg::Options::default();
options.fontdb_mut().load_system_fonts();
let mut tree = svg2pdf::usvg::Tree::from_str(&svg, &options)?;
let pdf = svg2pdf::to_pdf(&tree, ConversionOptions::default(), PageOptions::default()).unwrap();
std::fs::write(output, pdf)?;