Export SVG to EMF using CLI ( Increase resolution almost 10x )
**Summary:** Inkscape CLI incorrectly scales up the resolution and DPI when exporting an SVG file to EMF format. The exported EMF file has a significantly higher resolution and DPI than the original SVG, resulting in unintended scaling. **Steps to Reproduce:** 1. Create an SVG file with a simple geometric shape. 2. Export the SVG to EMF using Inkscape's CLI: `inkscape sample_diagram.svg --export-type=emf --export-dpi=90 --export-filename=sample_diagram.emf` 3. Check the resolution of the resulting EMF file. **What happened?** - The EMF file was saved with a much higher resolution than expected. - The DPI of the EMF file was far greater than the specified --export-dpi=90 setting. - The resolution increased drastically (e.g., **SVG: 347x347 units → EMF: 5810x5810 pixels at \~1200 DPI**). **What should have happened?** - The exported EMF file should retain the same dimensions and proportions as the original SVG. - The resolution and DPI should respect the --export-dpi flag without unexpected scaling. **Sample attachments:** - sample_diagram.svg ![sample_diagram.svg](/uploads/1db576558a7594f021bcab4e39d8804e/sample_diagram.svg) - sample_diagram.emf [sample_diagram.emf](/uploads/bab905f130d824b48f9e7fba05c67389/sample_diagram.emf)(exported EMF file showing the issue) - Terminal output/logs: ``` SVG file saved: sample_diagram.svg EMF file saved: sample_diagram.emf SVG Resolution: 347.04 x 347.04 units EMF Resolution: 5810 x 5810 pixels at 1199.8861696072852 DPI ``` **Version info:** ``` # Run 'inkscape --debug-info' and paste output here Inkscape 1.4 OS: macOS 15.3.2 Installation method: Official package from inkscape.org ``` **Python Based Code:** ```python import matplotlib.pyplot as plt import subprocess import os import xml.etree.ElementTree as ET from PIL import Image def get_svg_resolution(svg_file): """Extracts viewBox width and height from the SVG file.""" try: tree = ET.parse(svg_file) root = tree.getroot() width = root.get("width") height = root.get("height") viewBox = root.get("viewBox") if viewBox: viewBox_values = list(map(float, viewBox.split())) width = viewBox_values[2] height = viewBox_values[3] print(f"SVG Resolution: {width} x {height} units") except Exception as e: print(f"Error extracting SVG resolution: {e}") def get_emf_resolution(emf_file): try: with Image.open(emf_file) as img: dpi = img.info.get("dpi", "Resolution info not available") print(f"EMF Resolution: {img.width} x {img.height} pixels at {dpi} DPI") except Exception as e: print(f"Error reading EMF resolution: {e}") def generate_svg(output_svg): """Generates a sample geometric plot and saves it as an SVG file.""" fig, ax = plt.subplots(figsize=(6, 6), dpi=300) # High-resolution figure # Draw some geometric shapes circle = plt.Circle((0.5, 0.5), 0.3, color='blue', fill=False, linewidth=2) rect = plt.Rectangle((0.2, 0.2), 0.4, 0.3, color='red', fill=False, linewidth=2) ax.add_patch(circle) ax.add_patch(rect) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_aspect('equal') ax.axis('off') fig.savefig(output_svg, format='svg', bbox_inches='tight', dpi=300) print(f"SVG file saved: {output_svg}") def convert_svg_to_emf(input_svg, output_emf): """Converts an SVG file to an EMF file using Inkscape.""" inkscape_path = "/Applications/Inkscape.app/Contents/MacOS/inkscape" # macOS path # inkscape_path = "C:\Program Files\Inkscape\bin\inkscape.exe" # Windows path try: subprocess.run([ inkscape_path, "--export-type=emf", "--export-dpi=90", # Set DPI "--export-filename", output_emf, input_svg ], check=True) print(f"EMF file saved: {output_emf}") except subprocess.CalledProcessError as e: print(f"Error converting SVG to EMF: {e}") # Define file paths output_svg = "sample_diagram.svg" output_emf = "sample_diagram.emf" # Run the functions generate_svg(output_svg) convert_svg_to_emf(output_svg, output_emf) # Get and print resolutions get_svg_resolution(output_svg) get_emf_resolution(output_emf) ```
issue