#svg #pdf #convert #embedding #font #image #svg2pdf

vl-convert-pdf

Crate to convert SVG to PDF with embedded text

10 stable releases

new 1.4.0 Apr 15, 2024
1.3.0 Mar 13, 2024
1.2.4 Feb 27, 2024
1.2.3 Jan 27, 2024
0.14.0 Oct 2, 2023

#1694 in Text processing

Download history 6/week @ 2024-01-06 28/week @ 2024-01-13 28/week @ 2024-01-20 125/week @ 2024-01-27 10/week @ 2024-02-10 49/week @ 2024-02-17 152/week @ 2024-02-24 67/week @ 2024-03-02 188/week @ 2024-03-09 25/week @ 2024-03-16 7/week @ 2024-03-23 35/week @ 2024-03-30 18/week @ 2024-04-06

119 downloads per month
Used in 2 crates (via vl-convert-rs)

BSD-3-Clause

27KB
555 lines

vl-convert-pdf

This crate builds on top of the excellent svg2pdf project (created by the typst team) to convert SVG images to PDF files with embedded text. svg2pdf supports converting text into geometric paths using the usvg library, but it doesn't yet support embedding text (which is required for text selection, text copying, screen readers, etc.).

This project uses svg2pdf to handle everything in the SVG image except text, and then adds an embedded text layer on top using the pdf-writer library (also created by the typst team). The text embedding logic handles TrueType fonts and is heavily inspired by the implementation in the typst typesetting project.

In the future, it would be great if the text embedding logic in typst could be extracted and used by svg2pdf (making this crate unnecessary), but in the meantime this crate will maintain an independent implementation of text embedding.

Many thanks to the typst team for their support in https://github.com/typst/svg2pdf/issues/21.

Example

See examples/pdf_conversion.rs for example usage

Dependencies

~16MB
~159K SLoC