Inkscape bridge extensions for ImageJ/R/PyMOL/Processing

Dear all,
With Martin Owens, we’ve created Inkscape extensions that can request figure panels from ImageJ, R or Processing code that are supposed to help with making figure content more flexible and reproducible. I’ve put some slides here:

See this thread for a few examples:

Detailed installation procedure is described here.


Success reports on different systems:
OsX: 10.11.6; 10.15; 10.17 (Inkscape1.1-dev, Inkscape1.1rc, Inkscape 1.1)
Ubuntu 20.04 (Inkscape 1.2-dev, Inkscape 1.1)
Windows7 (Inkscape 1.1)


For those who’re looking for how to use the extensions, and for the source code: the repository is mentioned on the first slide (but doesn’t seem clickable on the f1000research embedded viewer).

Here’s the quick link:


Thanks @imagejan for the link.
Here is the installation details:


Configuring the ImageJ link, this is what my setup info shows

This is how it looks on Windows

Configuring the R link, this is what my setup info shows

And this is what my Processing setup info looks like

Hello @jerome.

This is very nice.

Since I can also create R plots with ImageJ images in Inkscape by changing the R plot device i would see a benefit in also transferring the R (or IJ macro) code directly to Inkscape to make a reproducible self running Inkscape instance with your plugin (just like rmarkdown).

Is there an API (command line args at Inkscape startup) available to transfer the code to your panels?

Thanks Marcel,
Yes Bio7 already has such a good IJ/R integration!

The panel code is just part of the description node of the object so the easiest I could think of woul be to copy valid svg in the clip board in bio7 and paste it in inkscape.

Then the code is simply wrapped into a template and passed to RScript, see:

Inkscape also has a command line interface that definitely makes it possible to modify an existing svg document, but, to my limited knowledge, not modify the currently open document.

1 Like

Thanks for the explanation @jerome

I think this becomes easier than I thought in R by simply saving an *.svg template with the R code as description:

And thanks to the new Raw String literals in Java 15 to write *svg in Java.


Hello @jerome,

this is my first Bio7 script attempt for your plugin. A simple Groovy script which writes the XML with the Object description (the R code from the current opened Bio7 R editor).

In addition it writes the current R workspace to the *svg file location (for images as vector or matrices) and adds the load statement as the first line:

Export script for R code to *.svg!
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.swt.widgets.Display;

Display display = Util.getDisplay();
display.asyncExec(new Runnable() {
	public void run() {
		IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if (editor instanceof REditor) {
			String path = Bio7Dialog.saveFile("*.svg");
			String pathRData = path.replace(".svg", ".RData").replace("\\", "/");
			if (RServe.isAlive()) {
				RServeUtil.evalR("save(file=\"" + pathRData + "\")", null);
				System.out.println("Rserve not running. R workspace not saved!");
			IDocumentProvider dp = editor.getDocumentProvider();
			IDocument doc = dp.getDocument(editor.getEditorInput());
			String rCode = doc.get();
			String svgTemplate = svgString(pathRData, rCode);
			if (path != null) {
				File fil = new File(path);
				FileWriter fileWriter = null;
				try {
					fileWriter = new FileWriter(fil);
					BufferedWriter buffWriter = new BufferedWriter(fileWriter);
					buffWriter.write(svgTemplate, 0, svgTemplate.length());
				} catch (IOException ex) {

				} finally {
					try {
					} catch (IOException ex) {

		} else {
			Bio7Dialog.message("Please open a R file!");



public String svgString(pathRData, rCode){
String svgTemplate = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="210mm" height="297mm" viewBox="0 0 210 297"
	version="1.1" id="svg5" xmlns=""
	<defs id="defs2" />
	<g id="layer1" transform="matrix(1,0,0,1.0000046,0,-1.1750488e-4)">
		<desc id="desc9">load(file='"""+pathRData+"')\n"+rCode+"""
		<rect style="fill:#f9f9f9;stroke-width:0.264583" id="rect31"
			width="104.66726" height="63.756706" x="19.658318" y="25.502682">
			<desc id="desc113">#RCode</desc>
return 	svgTemplate;

Resulted Inkscape (development version):

1 Like

That looks excellent, it’s all that’s needed to have this rect rendered, and your svg file can also be imported into, say, another figure in progress and keep its runnable code.
:star_struck: :star_struck:

It seems excellent, but I have issue with the installation. I work on Mac OS Big Sur with Anaconda distribution installed.
My issue is the following: when installing Extension Manager, I have an error from Inkscape that claims that virtualenv-python is not installed. I don’t know how to fix it.

There’s a lot of ongoing work for the extension manager (Activity · Inkscape / Inkscape Extras / extension-manager · GitLab).
In the meantime you don’t really need it, you can simply follow the installation steps and requirements at Martin Owens / inkscape-imagej-panel · GitLab

I have only tested the whole thing on 10.11 el capitan and 10.15 catalina, not on bigsur, so I would be interested in your feedback.


OK, I installed the extensions in the user extension folder, and it works now.
And It works on BigSur

1 Like

Hello @Jerome, just one thing I realized. When saving the XML embedded text it’s the pure editor text.

Inkscape however seems to load the XML-Text for the description.

In the sceenshot I sent you see that the < is not displayed. In the Inkscape panel it must be given as &lt;
So some conversions needs to be done:

Or there is an easier way to save the text for the Inkscape object description.

Hi Marcel,

Yes xml special characters are escaped in the svg as shown in the attached screenshots.
I found this article that shows an easy way of doing this from java: Escaping XML Special Characters in Java String - GeeksforGeeks


ImageJ macro code snippet in inkscape descripion:

How it is saved in the svg file:

Thanks Eric, great to see you got it working.

Thank @jerome I already replaced the Strings:

/*XML replacements!*/
rCode = rCode.replace("&", "&#38;");
rCode = rCode.replace("<", "&#60;");
rCode = rCode.replace(">", "&#62;");
rCode = rCode.replace("\"", "&#34;");
rCode = rCode.replace("'", "&#39;");

I also had to change the XML template. But now it is running fine after a correct installation.

Result (with last loop plot only):

The only thing I noticed is that a *.png file is embedded. I think it would be nice if a *.svg could be optionally used for R plots which can be easily exported with the R device.

1 Like

Excellent, thanks for the screenshot!
I agree that svg should be an option and it’s definitely possible.


What is the use case for this extension? Interaction w/ Scientifig?

The rationale is to include fully reproducible content directly from Inkscape. This way, the final svg figure can include the source code needed to render the panel images inside panel description. This brings full traceability of methods (code) used to generate figures, and also preserves links to raw data files. Because it works from the final layout software, it’s also easy to modify just a panel in a final figure, or create figure templates that you can apply to new source data. (existing figure building plugins all can export svg that Inkscape can read, so they can absolutely be used upstream in the figure creation process if needed)


So, you expect that someone is going to make figures in ImageJ instead of Powerpoint or Word? I’ve considered doing so, but never actually got around to it.

These figures need to be embedded in a PDF or Word document at some point to get published, unless you’re a mathematician/physicist using LaTeX. I like the idea, but I’m certain that I’ll never use it for an article, and I can’t think of anyone who can use these tools who actually will.

That’s really what I’m asking about (the demographics of the users as well as the specific use case), which is why I mentioned Scientifig.

Adding the link to the video introduction I did for OME2021 community meeting.