Giter Club home page Giter Club logo

svg2pdf's Introduction

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 path = "tests/svg/custom/integration/matplotlib/time_series.svg";
let svg = std::fs::read_to_string(path)?;

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

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

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

In general, a large part of the SVG specification is supported, including features like:

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

Unsupported features

Among the unsupported features are currently:

  • The spreadMethod attribute of gradients
  • Filters
  • Text will be converted into shapes before converting to PDF
  • Raster images are not color managed but use PDF's DeviceRGB color space
  • A number of features that were added in SVG2

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.

svg2pdf's People

Contributors

reknih avatar laurmaedje avatar laurenzv avatar eqt avatar frozolotl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.