Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding simple SVG provokes: ValueError: could not convert string to float: 'm' #356

Closed
nova-03 opened this issue Mar 8, 2022 · 4 comments

Comments

@nova-03
Copy link

nova-03 commented Mar 8, 2022

FPDF2 is a great project and I am very happy that fpdf2 was expanded with the SVG support early this year. Thank you for that!

While adding a simple SVG like this

pdf.image('search.svg', 165, 105, 40, 0)

Here is the content of search.svg:

<svg width="15" height="15" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg">
  <path fill="#555555" d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/>
</svg>

I get an ValueError: "could not convert string to float: 'm'"
which has been thrown in svg.py at line 690

I am using Python 3.9.2 with the latest version of the master fpdf2 branch (2.5.1)

Thanks in advance!

@nova-03 nova-03 added the bug label Mar 8, 2022
@Lucas-C Lucas-C added the svg label Mar 8, 2022
@Lucas-C
Copy link
Member

Lucas-C commented Mar 8, 2022

Thank you for reporting this bug @nova-03!
And thanks for providing the SVG file.

I'll get a look at it soon.
Ping @torque for information

@Lucas-C
Copy link
Member

Lucas-C commented Mar 8, 2022

The full stack trace:

Traceback (most recent call last):
  File "./issue_356.py", line 16, in <module>
    pdf.image('search.svg', 165, 105, 40, 0)
  File "/opt/fpdf2/fpdf/fpdf.py", line 251, in wrapper
    return fn(self, *args, **kwargs)
  File "/opt/fpdf2/fpdf/fpdf.py", line 2781, in image
    return self._vector_image(img, x, y, w, h, link, title, alt_text)
  File "/opt/fpdf2/fpdf/fpdf.py", line 2852, in _vector_image
    svg = SVGObject(img.getvalue())
  File "/opt/fpdf2/fpdf/svg.py", line 776, in __init__
    self.convert_graphics(svg_tree)
  File "/opt/fpdf2/fpdf/svg.py", line 826, in convert_graphics
    self.build_group(root_tag, base_group)
  File "/opt/fpdf2/fpdf/svg.py", line 1012, in build_group
    pdf_group.add_item(self.build_path(child))
  File "/opt/fpdf2/fpdf/svg.py", line 1034, in build_path
    svg_path_converter(pdf_path, svg_path)
  File "/opt/fpdf2/fpdf/svg.py", line 740, in svg_path_converter
    numbers, svg_path = _read_n_numbers(svg_path[read_idx:], read_count)
  File "/opt/fpdf2/fpdf/svg.py", line 690, in _read_n_numbers
    return tuple(float(num) for num in numbers), leftover.lstrip()
  File "/opt/fpdf2/fpdf/svg.py", line 690, in <genexpr>
    return tuple(float(num) for num in numbers), leftover.lstrip()
ValueError: could not convert string to float: 'm'

@Lucas-C
Copy link
Member

Lucas-C commented Mar 8, 2022

Fixed!

@nova-03
Copy link
Author

nova-03 commented Mar 8, 2022

Great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants