Is there a D3.js way to convert a text element into a path element?
So when I grasp the generated svg, I could keep my the texts shapes.
We can have Inkscape convert the text into editable objects. First, enter your line of text, and then go to the Path menu and choose “Object to Path“. Inkscape will then convert each letter into its own shape.
There is also a newly added node module called svg-text-to-vector that definitely does so. You simply have to serve the svg file, and it will return it with all the text tags within converted to path.
You may load and save as a File, Base64, Buffer or SVG String.
Example
var options={
load:'file.svg',
save:'file-convert.svg'
}
const convert = await svgTextPath.getPath(options);
Also supports adding fonts on both runtime and manually. Font names & paths load from svg-text-to-vector/config/fonts.json file
Runtime
var font={'name':'Lexend Tera','path': '/lexend_tera.ttf'}; const addFonts = await svgTextPath.push(font);
Manual
{ "font":[ { "name":"Times New Roman", "path":"./public/fonts/times.ttf" } ] }
{ "font":[ { "name":"Times New Roman", "path":"./public/fonts/times.ttf" }, { "name":"Anton", "path":"./public/fonts/anton.ttf" } ] }
Click here for convert to path sample file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With