【问题标题】:Fastest way to convert SVG to EMF repeatably using Inkscape and Python使用 Inkscape 和 Python 将 SVG 重复转换为 EMF 的最快方法
【发布时间】:2023-02-21 09:45:24
【问题描述】:

蟒蛇 3.9.0 墨景0.92

我使用 Inkscape 将 SVG 转换为 EMF,但这需要太多时间。

简单示例代码

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

虽然它取决于输入文件,但每次调用 'convert_svg_to_emf' 至少需要几秒钟。但是当我尝试直接从 Inkscape 转换它时,输出文件几乎立即出现。所以我假设应用程序的“打开”和“退出”子进程运行收取大部分处理时间。

有什么方法可以让它更快吗?

我的期待

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.

【问题讨论】:

    标签: python python-3.x subprocess inkscape


    【解决方案1】:

    Inkscape 提供了一些commandline options。最有效的方法是使用管道命令,或以 Shell 模式运行 Inkscape。从示例中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      • 2012-08-10
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多