document-svg 2.0.2

Convert PDF, Word, Excel, PowerPoint, diagram and CAD files into one SVG per page, locally — a Rust library and the docsvg command
Documentation
//! Create one SVG page directly from the public IR and SVG modules.

use std::fs::{self, File};
use std::io::BufWriter;
use std::path::PathBuf;

use document_svg::ir::{IDENTITY, Node, Page, Paint, SourceMeta, Stroke, TextAnchor, TextRun};
use document_svg::svg::{SvgOptions, write_page};
use document_svg::{Error, Result};

fn main() -> Result<()> {
    let output_path = std::env::args_os()
        .nth(1)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("output/custom.svg"));
    if let Some(parent) = output_path.parent() {
        fs::create_dir_all(parent)?;
    }

    let mut page = Page::new(1, 320.0, 180.0, "custom");
    page.title = "Public IR example".into();
    page.description = "A path and editable text generated by document-svg".into();

    page.nodes.push(Node::Path {
        id: "card".into(),
        d: "M 20 20 H 300 V 160 H 20 Z".into(),
        fill_rule: "nonzero".into(),
        fill: Paint::solid("#E8F1FF"),
        stroke: Stroke {
            paint: Paint::solid("#246BCE"),
            width: 2.0,
            ..Stroke::default()
        },
        transform: IDENTITY,
        clip_id: None,
        meta: SourceMeta {
            kind: "shape".into(),
            source_id: "example-card".into(),
            semantic_role: "background".into(),
            ..SourceMeta::default()
        },
    });

    page.nodes.push(Node::Text {
        id: "message".into(),
        x: 160.0,
        y: 98.0,
        runs: vec![TextRun {
            text: "Hello, SVG!".into(),
            font_size: 24.0,
            bold: true,
            fill: Paint::solid("#123B72"),
            ..TextRun::default()
        }],
        anchor: TextAnchor::Middle,
        transform: IDENTITY,
        opacity: 1.0,
        stroke: Stroke::default(),
        clip_id: None,
        meta: SourceMeta {
            kind: "text".into(),
            source_id: "example-message".into(),
            semantic_role: "heading".into(),
            alt_text: "Hello, SVG!".into(),
            ..SourceMeta::default()
        },
    });

    let file = File::create(&output_path).map_err(Error::from)?;
    write_page(&page, BufWriter::new(file), SvgOptions::default())?;
    println!("wrote {}", output_path.display());
    Ok(())
}