-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add SVG #351
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
Comments
Can you do that from the Word application UI? |
I haven't tried it myself, but it seems like it: |
I suspect it translates them into Windows Metafile Format (WMF) and stores them that way. You'd need to try it and then inspect the .docx file (it's a zip archive) and see what the image was that got included. I expect the file extension of the image file name would reliably indicate the underlying file type its stored as. |
I guess the documentation is outdated, as this approach does not let me insert an svg into the word document. So I assume the limitation lays with word itself? Then I need to look into how I can convert svg to png in Python. Thanks for your response. |
This page has some insights on why it might not be working for you: It could be your PowerPoint version is not the very latest; I know mine isn't :) It's still not clear whether the new PowerPoint 2016 supports SVG files natively or whether they are just converted to WMF/EMF and stored that way, like it does with PDF/EPS images. |
A PR related to this is pending #798 |
Thank you to python-docx, this is very useful software. I had done to embed svg images with python-docx. this is a part of my BTW, I found the PR and this is just a sample workaround for (this preview from Word android)
|
Nice, @kuri65536, thanks for posting this :) |
@kuri65536 - Thanks for the nice workaround! For anyone else still waiting for the PR, @kuri65536 's code caused a small hiccup in my code. Specifically, import re
def _ImageHeaderFactory(stream):
stream.seek(0)
buf = stream.read(32).decode("utf-8")
while re.match(r"\s*\<\?|\s*\<\!", buf):
m = re.match(r"(?:\s*<[\s\S]*?>\s*)+", buf)
if m:
buf = buf[m.end(0) :]
if not m or len(buf) < 4:
buf += stream.read(32).decode("utf-8")
if buf.startswith("<svg"):
stream.seek(0)
return Svg.from_stream(stream)
assert default_factory is not None
return default_factory(stream) |
It's been some time, any news or actual guide how to add an svg image to the docx template file? |
If it might help, Here are 2 Word with a similar image in PNG and SVG that have been added in the same place. I have also extracted the files and pretty-formatted the XML files for easier comparison |
Hi, I had a first try at implementing this, but have only tested using simple SVGs. The files open without issues in Word on my Mac Mini. Any feedback welcome. I haven't written any tests yet. |
See issues python-openxml#351, python-openxml#651, python-openxml#659. (cherry picked from commit 8f54818)
Uh oh!
There was an error while loading. Please reload this page.
Is it possible to add SVG to the document? For instance an svg-string such as
< svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1">
< rect width="200" height="100" stroke="black" stroke-width="6" fill="green" />
</ svg>
would be perfect. Or just a svg file?
The text was updated successfully, but these errors were encountered: