Fastest Way to Convert Svg to Emf Repeatably Using Inkscape and Python

Python 3.9.0 Inkscape 0.92

I use Inkscape to convert SVG to EMF, however it takes too much time.

Simple example code

import subprocess

def convert_svg_to_emf(input_svg_path, output_emf_path):
    # This method takes ~1 seconds
    subprocess.run([
        "C:\\Inkscape\\Inkscape.exe", # Inkscape executor path
        input_svg_path, # Input SVG file
        "--export-emf",
        output_emf_path # Output EMF file
    ])

# Assume I have 100 files to convert
for i in range(100):
    convert_svg_to_emf(f"svg{i}.svg", f"emf{i}.emf")

# This script takes ~100 seconds

Although it depends on input files, but every single call of 'convert_svg_to_emf' takes at least few seconds. But when I try converting it from Inkscape directly, a output file appears almost immediately. So I presume 'opening' and 'quitting' of the application by subprocess.run charges most processing time.

Is there any method to make this faster?

My expectation

inkscape = open_inkscape() # Keep opening Inkscape app

for i in range(100):
    inkscape.convert_svg_to_emf(f"svg{i}.svg", f"emf{i}.emf")

inkscape.quit() # Quit the app after all work done

# This script conducts 'opening' and 'quitting' just once regardless of number of files.

1 Answer

Inkscape offers some commandline options. The most efficient way is to use the pipe command, or to run Inkscape in Shell Mode. From the examples:

cat my_file.svg | inkscape --pipe --export-filename=my_file.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest