You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys, I'm new to fpdf and I'm loving it, mainly because of the new svg feature. But I had a simple issue with it.
While parsing a svg I've got a ValueError: could not convert string to float: '.31512px'
Then I simply manually removed the 'px' strings at the stroke-width value in the svg file.
But then I've got a ValueError: could not convert string to float: 'e'
So I also replaced all the 'e-' strings from the svg files and it worked fine.
Since python float() function works fine with exponential notation, it seems like fpdf is breaking something before trying to float those values. Maybe it is splitting those strings before processing or something.
karthurdnt
changed the title
Issue with parsing svg with values in exponential notation
Issue with parsing svg with values in px units and in exponential notation
Mar 30, 2022
If it is of any use, this is how I tweaked the svg file so it would bypass the bug:
import re
with open('modelo.svg', 'r') as f1, open('modelo2.svg', 'w') as f2:
svg = f1.read()
svg = svg.replace('px','')
e_numbers = re.findall(r"\d+\.\d+e-\d+|\d+e-\d+",svg,re.M) # finds x.xe-x or xe-x numbers
e_numbers.sort(key=len,reverse=True) # sorts the list from longest to shortest to prevent a 1e-1 replacing a 11e-1
for x in e_numbers:
svg = svg.replace(x,f'{float(x):.10f}'.rstrip('0'))
f2.write(svg)
Hi guys, I'm new to fpdf and I'm loving it, mainly because of the new svg feature. But I had a simple issue with it.
While parsing a svg I've got a ValueError: could not convert string to float: '.31512px'
Then I simply manually removed the 'px' strings at the stroke-width value in the svg file.
But then I've got a ValueError: could not convert string to float: 'e'
So I also replaced all the 'e-' strings from the svg files and it worked fine.
Since python float() function works fine with exponential notation, it seems like fpdf is breaking something before trying to float those values. Maybe it is splitting those strings before processing or something.
Minimal code
Reference of a simplified svg file:(only one path object) reproducing the cited issue:
And
Environment
fpdf2
2.5.1 (latest version of fpdf2 from the git repository)The text was updated successfully, but these errors were encountered: