svg2pdf-wasm
v0.2.1
Published
## ๐ Overview `svg2pdf-wasm` is a **WebAssembly-compatible Rust package** that allows you to: - Convert **SVG to PDF**. - Add **custom text** using a loaded **Base64 font**. - **Export** the final PDF as a byte array (`Vec<u8>`) for client-side use.
Readme
svg2pdf-wasm Documentation
๐ Overview
svg2pdf-wasm is a WebAssembly-compatible Rust package that allows you to:
- Convert SVG to PDF.
- Add custom text using a loaded Base64 font.
- Export the final PDF as a byte array (
Vec<u8>) for client-side use.
This package is designed for WASM/WebAssembly environments, allowing SVG-PDF conversion directly in web apps.
๐ฏ Example Usage (Complete Flow)
import init, {
PdfConverter,
svg_to_pdf_sync, // if you built without threads
svg_to_pdf_threaded, // only present with `--features threads`
init_thread_pool // only present with `--features threads`
} from "svg2pdf-wasm";
navigator.hardwareConcurrency // must be โฅ2
async function generatePDF() {
await init();
// THREADS BUILD
if (init_thread_pool) {
await init_thread_pool(navigator.hardwareConcurrency || 4);
}
const base64SVG = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwv...";
const base64Font = "UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA==";
const converter = new PdfConverter();
await converter.load_base64_font(base64Font);
const pdfData = await converter.svg_to_pdf_threaded(base64SVG, 1.0);
// await converter.svg_to_pdf_sync(base64SVG, 1.0);
const blob = new Blob([pdfData], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
window.open(url);
}
generatePDF();