I am used to use xclip
to copy/paste png files into libreoffice writer.
The command I use is:
xclip -selection clipboard -t "image/png" -i <path_to_file>
Now, I want to copy/paste svg images, but I cannot figure out what is the appropriate "target" option.
I have tried many different -t arguments, for example:
xclip -selection clipboard -t "image/svg" -i <path_to_file>
xclip -selection clipboard -t "image/svg+xml" -i <path_to_file>
xclip -selection clipboard -t 'application/x-openoffice-drawing;windows_formatname="Drawing Format"' -i <path_to_file>
It almost worked with the following commands, but the image is pasted in a raster format rather than svg:
xclip -selection clipboard -t 'application/x-openoffice-emf;windows_formatname="Image EMF"' -i <path_to_file>
xclip -selection clipboard -t 'application/x-openoffice-wmf;windows_formatname="Image WMF"' -i <path_to_file>
I can copy/paste svg files to libreoffice write using ctrl+c/ctrl+v, but I would like to do it via command line, preferably by using xclip
. Is there a way to do it? Any help is appreciated.
By the way, I'm on Ubuntu 18.04 and I'm using xclip version 0.12.
In my experience, LibreOffice seems…
I've had no luck either trying to paste SVG code directly into LibreOffice via xclip to the clipboard selection… didn't get that to work with any target name, and the cases where I did get a copy/pasted image from some other app into LibreOffice were, like you experienced, not imported as SVG vector data but as raster graphics. BUT:
the following (pasting an URI instead of direct SVG code) works for me:
echo "file://<path_to_file>" |xclip -in -selection "CLIPBOARD" -verbose -target text/uri-list
it seems to also work with just the path without the "file://" uri scheme prefix:
echo "<path_to_file>" |xclip -in -selection "CLIPBOARD" -verbose -target text/uri-list
and it seems to (mostly) work with remote URLs instead of local file URIs… at least in principle. I just successfully tried with this URI:
https://openclipart.org/download/187787/Flower-Christmas-Flower.svg
However, it seems that the SVG import of LibreOffice has problems (not just when importing via clipboard but also when explicitly importing via Insert->Image) with some SVGs that other programs seem to display without problems, especially mathematical formulae on wikipedia (I believe wiki uses MathJax to render them to SVG). For example, the following svg from wikipedia will not be pasted correctly into LibreOffice, even if I download it and rename it to "foo.svg" and try to explicitly import it: https://wikimedia.org/api/rest_v1/media/math/render/svg/6d4475fbd112aad0bedebebac14a4fa6b220de74
And conversely, the import via clipboard will also fail on more complicated URLS even if it's an SVG file that LibreOffice has no problem with per se (with a less complicated local file URI), for example, this one fails as is:
https://en.wikipedia.org/wiki/Special_relativity#/media/File:World_line.svg
but will import just fine if imported as a local file.