- Notifications
You must be signed in to change notification settings - Fork1.2k
Add basic support for adding SVG pictures to docx files#1343
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This is the simple code I've been testing with: importdatetimefromdocximportDocumentSVG="""<svg version="1.1" width="300" height="200" xmlns="http://www.w3.org/2000/svg"> <rect width="100%" height="100%" fill="red" /> <circle cx="150" cy="100" r="80" fill="green" /> <text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text></svg>"""svg_filename="drawing.svg"withopen(svg_filename,"w")asf:f.write(SVG)document=Document()now=datetime.datetime.now()document.add_heading("Document Title",0)document.add_heading(f"{now}",0)document.add_picture(svg_filename)document.save("demo.docx") |
mzaanen commentedMar 11, 2024
Thank you so much for this fix. I just could not get QR codes sharp in a docx document. First I used .png files using segno and did "add_picture" in python-docx. The .png images are sharp, but the add_picture resizes and blurs it all. Result is a rescaled and blurred image in the .docx. Now I make .svg files using segno and I use your branch (https://github.com/takis/python-docx.git, master) to do the add_picture and it is now spot on; no blurring, sharp as anything. You saved my day ! Thanks again. |
michaelarfreed commentedApr 24, 2024
I'd love to see this PR approved! It is a great fix for a feature that windows supports. I need this feature for code I'm developing, and can't rely on a branch outside of the main branch, so would love to see the PR approved !! |
I've just created new pull request replacing this one: |
See issues#351,#651,#659.
This replaces this pull request from two years ago:
#1107