← 返回首页
Add basic support for adding SVG pictures to docx files by takis · Pull Request #1343 · python-openxml/python-docx · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Add basic support for adding SVG pictures to docx files#1343

Closed
takis wants to merge 0 commit into
python-openxml:masterfrom
takis:master
Closed

Add basic support for adding SVG pictures to docx files#1343
takis wants to merge 0 commit into
python-openxml:masterfrom
takis:master

Conversation

Copy link
Copy Markdown

takis commented Feb 22, 2024

See issues #351, #651, #659.

This replaces this pull request from two years ago:
#1107

Copy link
Copy Markdown
Author

takis commented Feb 22, 2024

This is the simple code I've been testing with:

import datetime from docx import Document SVG = """<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" with open(svg_filename, "w") as f: 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")

Copy link
Copy Markdown

mzaanen commented Mar 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.

Copy link
Copy Markdown

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 !!

Copy link
Copy Markdown
Author

takis commented May 2, 2024

I've just created new pull request replacing this one:
#1386

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Footer

© 2026 GitHub, Inc.