How to position one SVG onto another SVG at a specified position using python3 or INKSCAPE command line?

Viewed 57

I have 2 files Canvas.svg and Rectangle.svg. I want to place the Rectangle.svg onto Canvas.svg at X-mm,Y-mm co-ordinates. Is it possible to do this operation using python3 or INKSCAPE command line ?

First preference is any python3 implementation.

enter image description here

Thanks in Advance !!!

1 Answers

I will suggest a wrapper file that references both Canvas.svg and Rectangle.svg:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  width="600" height="400" viewBox="0 0 600 400">
    <image xlink:href="Canvas.svg" width="600" height="400"/>
    <image xlink:href="Rectangle.svg" width="200" height="100"
      transform="translate(100, 200)"/>
</svg>

As an example: With the command inkscape --export-type="pdf" wrapper.svg a PDF file will be generated what is 600x400 pixel and has a default DPI of 96, resulting in a PDF with the size of 6.25in x 4.17in. The DPI can be controlled by the flag --export-dpi=DPI.

It is up to you calculate the sizes appropriate for metric units :-)

Reference: MAN PAGE | Inkscape

PS: I know that the namespace http://www.w3.org/1999/xlink can be omitted when using SVG in a browser, but here it is needed...

Related