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
As far as I know currently, inline SVG is not supported #75, and to use inline SVG within WeasyPrint, in the meantime as a workaround we use data: URLs. Steps we do:
Find all SVG elements on the page
Convert them to base64 and set them as background.
Remove all child nodes from the SVG root element
Everything has been working just fine before I tried to set width and height for the root SVG element.
If you set width and height attributes it breaks pdf rendering with the following exception: Failed to draw an SVG image at None: cairo returned CAIRO_STATUS_INVALID_MATRIX: b'invalid matrix (not invertible)'
But if you set width and height through CSS style pdf renders normally.
So, I made a test html page with two exactly same circles, red(height and width attributes set on element), blue(width and height set through CSS style). Produced pdf has only the blue one.
There’s definitely a bug in WeasyPrint, but your example is a little bit weird. I’ll try to explain what’s going on.
WeasyPrint doesn’t support inline SVG (see #75) and your svg tags are actually seen as unknown tags. They’re common boxes, just as if they were spans.
The second one has width and height set in CSS, so the block with the background is displayed correctly. But the first one has no width and height set (the width and height attributes are ignored, just as they would be on HTML tags) and no child: it’s size is thus 0px × 0px. The error happens because WeasyPrint tries to draw an SVG with no size.
Without the error, the image wouldn’t be drawn, and you’d get the same rendering. You can replace your svg tags by spans and render them on a browser, you’ll get what WeasyPrint gives: a blue circle with no red circle.
So, we’ll fix the error but it won’t change the rendering. Fixing #75 would draw the red circle, because the svg would be seen as what it really is and thus take care of the width and height properties.
As far as I know currently, inline SVG is not supported #75, and to use inline SVG within WeasyPrint, in the meantime as a workaround we use
data:
URLs. Steps we do:Everything has been working just fine before I tried to set width and height for the root SVG element.
If you set width and height attributes it breaks pdf rendering with the following exception:
Failed to draw an SVG image at None: cairo returned CAIRO_STATUS_INVALID_MATRIX: b'invalid matrix (not invertible)'
But if you set width and height through CSS style pdf renders normally.
So, I made a test html page with two exactly same circles, red(height and width attributes set on element), blue(width and height set through CSS style). Produced pdf has only the blue one.
weasyprint version: v52
The text was updated successfully, but these errors were encountered: