4 releases (breaking)

Uses new Rust 2021

0.4.0 Jun 10, 2022
0.3.0 Mar 6, 2022
0.2.2 Mar 1, 2022
0.2.1 Jan 19, 2022
0.1.0 Dec 6, 2021

#25 in Multimedia

Download history 53/week @ 2022-03-08 54/week @ 2022-03-15 55/week @ 2022-03-22 52/week @ 2022-03-29 62/week @ 2022-04-05 51/week @ 2022-04-12 120/week @ 2022-04-19 99/week @ 2022-04-26 79/week @ 2022-05-03 105/week @ 2022-05-10 63/week @ 2022-05-17 74/week @ 2022-05-24 82/week @ 2022-05-31 75/week @ 2022-06-07 74/week @ 2022-06-14 63/week @ 2022-06-21

305 downloads per month
Used in 3 crates

MIT/Apache

79KB
1.5K SLoC

svg2pdf

Build status Current crates.io release Documentation

Convert SVG files to PDFs.

This crate allows to convert static (i.e. non-interactive) SVG files to either standalone PDF files or Form XObjects that can be embedded in another PDF file and used just like images.

The conversion will translate the SVG content to PDF without rasterizing it, so no quality is lost.

Example

This example reads an SVG file and writes the corresponding PDF back to the disk.

let svg = std::fs::read_to_string("tests/example.svg").unwrap();

// This can only fail if the SVG is malformed. This one is not.
let pdf = svg2pdf::convert_str(&svg, svg2pdf::Options::default()).unwrap();

// ... and now you have a Vec<u8> which you could write to a file or
// transmit over the network!
std::fs::write("target/example.pdf", pdf).unwrap();

CLI

This crate also contains a command line interface. Install it by running the command below:

cargo install svg2pdf --features cli

You can then convert SVGs to PDFs by running commands like these:

svg2pdf your.svg

Supported features

  • Path drawing with fills and strokes
  • Gradients
  • Patterns
  • Clip paths
  • Masks
  • Transformation matrices
  • Respecting the keepAspectRatio attribute
  • Raster images and nested SVGs

Filters are not currently supported and embedded raster images are not color managed. Instead, they use PDF's DeviceRGB color space.

Contributing

We are looking forward to receiving your bugs and feature requests in the Issues tab. We would also be very happy to accept PRs for bug fixes, features, or refactorings!

If you want to contribute but are uncertain where to start, yo could look into filters like feBlend and feColorMatrix that can be implemented with transparency groups and color spaces, respectively. We'd be happy to assist you with your PR's, so feel free to post Work in Progress PRs if marked as such. Please be kind to the maintainers and other contributors. If you feel that there are any problems, please feel free to reach out to us privately.

Thanks to each and every prospective contributor for the effort you (plan to) invest in this project and for adopting it!

License

svg2pdf is licensed under a MIT / Apache 2.0 dual license.

Users and consumers of the library may choose which of those licenses they want to apply whereas contributors have to accept that their code is in compliance and distributed under the terms of both of these licenses.

Dependencies

~2.3–4MB
~78K SLoC