Error in importing svg files into canvas.

151 views
Skip to first unread message

Dhruv Agrawal

unread,
Aug 30, 2023, 6:56:41 AM8/30/23
to Paper.js
i am making an vector graphic editor using paper.js and during building , i am trying to add import of svg file feature....during this the svg file will easily get imported to canvas but it is showing error as i can't access each element of the svg file separately or each element of not resterizable and the whole files is moving in odd manner. 
Can anyone please why is this happen to me ?
Or some reference that can solve my problem.

Shannon Lin

unread,
Jan 30, 2024, 3:47:45 PM1/30/24
to Paper.js
im also attempting to work with imported SVGs in paper js, and im finding it quite difficult to see exactly how the svg gets converted to a paper js object. is there any documentation on the item after it gets imported? 

petejo...@gmail.com

unread,
Aug 26, 2024, 11:59:57 AM8/26/24
to Paper.js
One error I found in SVG import was files that contains an id that start with a number. Simple solution for this is to replace any id entries that start with a number e.g. id="1" with id="_1" in the onload event
        svg = svg.replace(/id="([0-9]*?)"/g, 'id="_$1"');
The other problem is an svg that contains text. To display corectly,  access to the font file  that was used is needed.  I import the svg to  a group an then iterate thought the children and the font in any text items to one that I have present on the system.
Reply all
Reply to author
Forward
0 new messages