#svg #pdf #convert #geometric #embedding #image #font

vl-convert-pdf

Crate to convert SVG to PDF with embedded text

10 stable releases

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

#1830 in Text processing

Download history 77/week @ 2024-07-24 19/week @ 2024-07-31 2/week @ 2024-09-11 3/week @ 2024-09-18 13/week @ 2024-09-25 1/week @ 2024-10-02

992 downloads per month

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

~10MB
~170K SLoC