Reputation: 619
I am trying to create a Python script that takes multiple one-page SVG files, converting them to a PNG file, and then combining them into one word document. But when inspecting the word document the images are partially corrupt with black ink covering more than half of the image.
The image inside the word document looks like this (shouldn't be covered in black ink);
Python code
from docx import Document
from wand.image import Image
from io import BytesIO
def create_word_document(input_files: list[str], output_docx: str):
doc = Document()
for svg_file in input_files:
with Image(filename=svg_file, format='svg') as img:
width, height = 600, 800
img.resize(width, height)
with img.convert('png') as converted:
png_bytes = converted.make_blob('png')
doc.add_picture(BytesIO(png_bytes))
doc.save(output_docx)
Upvotes: 0
Views: 49