Get started
From installing to showing the first page in your app. Most people are done in about five minutes.
1. Pick how you'll use it
You only need one of these. Choose by where you want to call it from.
npm installs into your project's node_modules, pip into the active environment's site-packages, and cargo install puts docsvg in ~/.cargo/bin.
From the command line
For converting files in a terminal or a CI job. If you have Rust, install with cargo. If not, download the file for your system from the Releases page.
cargo install document-svg --lockedNode.js / TypeScript
For converting inside a web or Electron app. Type definitions are included.
npm install document-svgPython
For converting inside scripts and data pipelines. Python 3.10 or newer.
python -m pip install document-svgRust
For building it into a Rust program.
cargo add document-svgnpm package page →PyPI package page →crates.io page →Rust API reference (docs.rs) →Download a ready-made command (Releases) →
2. Convert your first file
The same conversion works the same way from anywhere. Each example runs as written.
Convert a file to SVG pagesbash
docsvg report.pdf --output output/report
docsvg slides.pptx --output output/slides
docsvg architecture.drawio --output output/diagram --stencils path/to/stencils.xmlConvert PDF pages in parallelbash
docsvg report.pdf --output output/report --jobs 4 --max-pages 100Turn SVG pages back into PowerPoint, Word or other filesbash
docsvg reverse output/slides --output slides.pptx
docsvg reverse output/diagram --output diagram.drawio
docsvg reverse output/drawing --output drawing.dxfTidy up an existing SVG for where it will be usedbash
docsvg transform diagram.svg --output diagram.min.svg \
--minify --monochrome "#1e293b" --responsive --precision 1Convert and save SVG filesjavascript
const { convert } = require('document-svg')
const report = await convert('report.docx', 'output/report', { maxPages: 100 })
const needsReview = report.warnings.length > 0 ||
report.pages.some((page) => page.warnings.length > 0)
console.log(report.pageCount, needsReview)Get complete SVG strings for an in-app previewtypescript
import { preview } from 'document-svg'
const report = await preview('slides.pptx', { maxPages: 100 })
for (const page of report.pages) {
console.log(page.number, page.widthPoints, page.heightPoints)
// page.svg is the complete SVG XML string
}
console.log('review required:', report.needsReview)Render it in the browser without loading native codetsx
import { createSvgPreviewUrl, revokeSvgPreviewUrl } from 'document-svg/preview-ui'
const url = createSvgPreviewUrl(svgMarkup)
// <img src={url} alt="Office document preview" />
// when replacing the image or disposing of the view:
revokeSvgPreviewUrl(url)Turn SVG pages back into PowerPoint, Word or other filesjavascript
const { reverse } = require('document-svg')
const report = await reverse('output/diagram', 'diagram.drawio')
console.log(report.pageCount, report.warnings)Convert a file to SVG pagespython
from document_svg import convert
report = convert("input.pptx", "output/pptx", jobs=1, max_pages=500)
needs_review = bool(report["warnings"]) or any(
page["warnings"] for page in report["pages"]
)
print(report["page_count"], needs_review)Turn SVG pages back into PowerPoint, Word or other filespython
from document_svg import reverse
report = reverse("output/slides", "slides.pptx")
print(report["page_count"], report["warnings"])Convert a file to SVG pagesrust
use document_svg::{convert_path, ConvertOptions};
let options = ConvertOptions { jobs: 4, max_pages: 500, ..ConvertOptions::default() };
let report = convert_path("input.pdf", "output/pdf", &options)?;
println!("{} pages", report.page_count);Build an SVG page from your own shapes and textrust
use document_svg::ir::{IDENTITY, Node, Page, Paint, Stroke};
use document_svg::svg::write_page;
let mut page = Page::new(1, 320.0, 180.0, "custom");
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: Default::default(),
});
write_page(&mut std::fs::File::create("out.svg")?, &page)?;Turn SVG pages back into PowerPoint, Word or other filesrust
use document_svg::{svg_to_document, ReverseOptions};
let report = svg_to_document("output/slides", "slides.pptx", &ReverseOptions::default())?;
println!("{} pages", report.page_count);3. Check the result
Give it a new or empty output folder. Inside you get one SVG per page and one record of the conversion (conversion.json).
output/slides/
├── page-0001.svg
├── page-0002.svg
└── conversion.json- The record lists, as warnings, anything that could not be reproduced exactly.
- Finishing without an error is not the same as perfect. If there are warnings, have a person look at the pages.
- Even with no warnings, the pages are not guaranteed to match Office pixel for pixel. Text, for example, uses the fonts available where the SVG is viewed.
4. Show it in your app
Show each SVG as an image, for example with an image element. Don't paste the SVG's markup straight into your page's HTML.
The included display helpers do some basic checks, but they are not a filter that makes any SVG harmless.
5. Use it from tools you already have
GitHub Actions
Convert the documents a pull request changes, automatically.
Claude Code / Codex
Add it to your AI assistant as a plugin.
GitHub CLI
Use it as the gh docsvg command after running the installer in a local checkout.
6. If something goes wrong
- Ready-made packages exist for Windows, macOS and Linux, on both x64 and ARM64.
- Python on Alpine Linux has no ready-made package, so Rust and build tools are needed there.
- If the npm package installs but won't load, check that optional dependencies were installed and that Node.js matches your machine's CPU. Copying node_modules to another system won't work.
- The SVG pages display in current browsers, resvg, and librsvg 2.46 or newer.