7
$\begingroup$

I frequently include plots in my emails. The easiest and most reliable way I have found is to just capture a part of the screen using greenshot (Windows) and paste into the message.

Microsoft recently added SVG support to Office 2016 including Outlook. Hence, it should be possible to embed a nice resolution independent SVG plot created in Mathematica into an Outlook message.

Mathematica doesn't have a "Copy as SVG" menu option. But you can Export to a file, and then import it into you message, however, this is a lot of clicks.

So the question is: How to copy as SVG to the clipboard so that the process is simplified?

Note 1: a simple:

CopyToClipboard[ExportString[Plot[Sin[x], {x, 0, Pi}], "SVG"]] 

does not work.

Note 2: I already have the solution for Windows, so I am more sharing than asking. But there may be better solutions and also with support for other operating systems.

Note 3: SVG in email is a good idea in a controlled environment where you know that the recipient has an email client that supports it. For regular, non intranet email, better stick to traditional screenshots.

$\endgroup$

1 Answer 1

7
$\begingroup$

Under Windows, this can be done with NETLink by modifying code published here.

Needs["NETLink`"] WriteToClipboardSVG[g_] := Module[{png, strm, dataObject}, InstallNET[]; png = ExportString[g, "SVG"]; NETBlock[ strm = NETNew["System.IO.MemoryStream", ToCharacterCode[png]]; dataObject = NETNew["System.Windows.Forms.DataObject"]; dataObject@SetData["image/svg+xml", strm]; LoadNETType["System.Windows.Forms.Clipboard"]; Clipboard`SetDataObject[dataObject]]] 

This was done by opening an svg file with Internet Explorer and examining the examining the clipboard contents using ClipView tool, and some luck.

So you can now evaluate this:

WriteToClipboardSVG[Plot[Sin[x], {x, 0, Pi}]] 

and paste in Outlook 2016 and nice vector, rescalable plot.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.